<?php
namespace BP\En;
require_once("java/io/File.php");
require_once("java/io/Serializable.php");
require_once("java/io/IOException.php");
require_once("java/math/BigDecimal.php");
require_once("java/util/ArrayList.php");
require_once("java/util/Hashtable.php");
require_once("java/util/Set.php");
require_once("BP/DA/AtPara.php");
require_once("BP/DA/Cash.php");
require_once("BP/DA/Cash2019.php");
require_once("BP/DA/CashEntity.php");
require_once("BP/DA/DBAccess.php");
require_once("BP/DA/DBType.php");
require_once("BP/DA/DataColumn.php");
require_once("BP/DA/DataRow.php");
require_once("BP/DA/DataTable.php");
require_once("BP/DA/DataType.php");
require_once("BP/DA/Depositary.php");
require_once("BP/DA/Log.php");
require_once("BP/DA/LogType.php");
require_once("BP/DA/Paras.php");
require_once("BP/Sys/EnVer.php");
require_once("BP/Sys/EnVerDtl.php");
require_once("BP/Sys/GEDtlAttr.php");
require_once("BP/Sys/GloVar.php");
require_once("BP/Sys/MapAttr.php");
require_once("BP/Sys/MapAttrs.php");
require_once("BP/Sys/MapData.php");
require_once("BP/Sys/MapDtl.php");
require_once("BP/Sys/SysDocFile.php");
require_once("BP/Sys/SysEnum.php");
require_once("BP/Sys/SysEnumAttr.php");
require_once("BP/Sys/SysEnums.php");
require_once("BP/Sys/SystemConfig.php");
require_once("BP/Tools/StringHelper.php");
require_once("BP/Tools/StringUtils.php");
require_once("BP/WF/Template/FrmField.php");
require_once("BP/WF/Template/FrmFieldAttr.php");
require_once("BP/Web/WebUser.php");
abstract class Entity implements Serializable {
	protected static $serialVersionUID;	// long
	protected $_GetNewEntities;	// Entities
	protected $_HisUAC;	// UAC
	protected $_tmpEnMap;	// Map
	protected $_row;	// Row
	protected $_SQLCash;	// SQLCash
	private function __init() { // default class members
		$this->_GetNewEntities = NULL;
		$this->_HisUAC = NULL;
		$this->_tmpEnMap = NULL;
		$this->_row = NULL;
		$this->_SQLCash = NULL;
	}
	public static function __staticinit() { // static class members
		self::$serialVersionUID = 1;
	}
	public function getGetNewEntities () 
	{
		if (($this->_GetNewEntities == NULL))
		{
			$str = $this;
			$ensName = ($str . "s");
			$this->_GetNewEntities = ClassFactory::GetEns($ensName);
			if (($this->_GetNewEntities != NULL))
				return $this->_GetNewEntities;
			$al = ClassFactory::GetObjects("BP.En.Entities");
			foreach ($al as $o) 			{
				$ens = (( (($o instanceof Entities)) ? $o : NULL ));
				if (($ens == NULL))
				{
					continue;
				}
				if ((($ens->getNewEntity() . NULL) . $ens->getNewEntity()->equals($str)))
				{
					$this->_GetNewEntities = $ens;
					return $this->_GetNewEntities;
				}
			}
			throw new \RuntimeException(("@no ens" . $this));
		}
		return $this->_GetNewEntities;
	}
	public function getPKField () 
	{
		foreach ($this->getEnMap()->getAttrs() as $attr) 		{
			switch ($attr->getKey()) {
				case "OID":
					return $attr->getField();
				case "No":
					return $attr->getField();
				case "MyPK":
					return $attr->getField();
				default:
					break;
			}
			if (((($attr->getMyFieldType() == FieldType::$PK) || ($attr->getMyFieldType() == FieldType::$PKEnum)) || ($attr->getMyFieldType() == FieldType::$PKFK)))
			{
				return $attr->getField();
			}
		}
		throw new \RuntimeException((("@娌℃湁缁欍��?" . $this->getEnDesc()) . "銆戝畾涔変富閿��"));
	}
	public function getClassID () 
	{
		return $this;
	}
	protected function ExitsValueNum ($key, $val) // [String key, String val]
	{
		$ps = new Paras();
		$ps->Add("p", $val);
		$sql = (((((((("SELECT COUNT( " . $key) . " ) FROM ") . $this->getEnMap()->getPhysicsTable()) . " WHERE ") . $key) . "=") . $this->getHisDBVarStr()) . "p");
		return $Integer->parseInt(DBAccess->RunSQLReturnVal($sql, $ps));
	}
	public function GetDtlsDatasOfArrayList () 
	{
		$al = [];// 
		foreach ($this->getEnMap()->getDtls() as $dtl) 		{
			$al->add($this->GetDtlEnsDa_String($dtl->getEns()));
		}
		return $al;
	}
	public function GetDtlsDatasOfList () 
	{
		$al = [];// 
		foreach ($this->getEnMap()->getDtls() as $dtl) 		{
			$al->add($this->GetDtlEnsDa_String($dtl));
		}
		return $al;
	}
	public function GetDtlsDatasOfList_String ($pkval) // [String pkval]
	{
		$al = [];// 
		foreach ($this->getEnMap()->getDtls() as $dtl) 		{
			/* match: EnDtl_String */
			$al->add($this->GetDtlEnsDa_EnDtl_String($dtl, $pkval));
		}
		return $al;
	}
	public function GetDtlEnsDa_String ($EnsName) // [String EnsName]
	{
		$ens = ClassFactory::GetEns($EnsName);
		return $this->GetDtlEnsDa_Entities($ens);
	}
	public function GetDtlEnsDa_EnDtl_String ($dtl, $pkval) // [EnDtl dtl, String pkval]
	{
		try 
		{
			if (($pkval . NULL))
				$pkval = $this->getPKVal();
			$qo = QueryObject::constructor__Entities($dtl->getEns());
			$md = new MapDtl();
			$md->setNo($dtl->getEns()->getNewEntity());
			if (($md->RetrieveFromDBSources() == 0))
			{
				$qo->AddWhere_String_String($dtl->getRefKey(), $pkval);
				$qo->DoQuery();
				return $dtl->getEns();
			}
			switch ($md->getDtlOpenType()) {
				case $ForEmp:
					$qo->AddWhere_String_String($GEDtlAttr->RefPK, $pkval);
					$qo->addAnd();
					$qo->AddWhere_String_F($GEDtlAttr->Rec, $WebUser->getNo());
					break;
				case $ForWorkID:
					$qo->AddWhere_String_String($GEDtlAttr->RefPK, $pkval);
					break;
				case $ForFID:
					$qo->AddWhere_String_String($GEDtlAttr->FID, $pkval);
					break;
			}
			if (($md->getFilterSQLExp() . ""))
			{
				$strs = $md->getFilterSQLExp()->split("=");
				$qo->addAnd();
				$qo->AddWhere_String_F($strs[0], $strs[1]);
			}
			$qo->DoQuery();
			return $dtl->getEns();
		}
		catch (Exception $e)
		{
			throw new Exception((((("@在取[" . $this->getEnDesc()) . "]的明细时出现错误。[") . $dtl->getDesc()) . "],不在他的集合内�??"));
		}
	}
	public function GetDtlEnsDa_EnDtl ($dtl) // [EnDtl dtl]
	{
		try 
		{
			$qo = QueryObject::constructor__Entities($dtl->getEns());
			$qo->AddWhere_String_F($dtl->getRefKey(), $this->getPKVal());
			$qo->DoQuery();
			return $dtl->getEns();
		}
		catch (\RuntimeException $e)
		{
			throw new \RuntimeException((((("@在取[" . $this->getEnDesc()) . "]的明细时出现错误。[") . $dtl->getDesc()) . "],不在他的集合内�??"));
		}
	}
	public function GetDtlEnsDa_Entities ($ens) // [Entities ens]
	{
		foreach ($this->getEnMap()->getDtls() as $dtl) 		{
			if (($dtl->getEns()->getClass() == $ens->getClass()))
			{
				$qo = QueryObject::constructor__Entity($dtl->getEns());
				$qo->AddWhere_String_F($dtl->getRefKey(), $this->getPKVal());
				$qo->DoQuery();
				return $dtl->getEns();
			}
		}
		throw new \RuntimeException((((("@在取[" . $this->getEnDesc()) . "]的明细时出现错误。[") . $ens->getNewEntity()->getEnDesc()) . "],不在他的集合内�??"));
	}
	public function ToStringAtParas () 
	{
		$str = "";
		foreach ($this->getEnMap()->getAttrs() as $attr) 		{
			$str += ((("@" . $attr->getKey()) . "=") . $this->GetValByKey($attr->getKey()));
		}
		return $str;
	}
	public function ToEmptyTableField () 
	{
			/* match: Entity */
		return $this->ToEmptyTableField_Entity(NULL);
	}
	public function ToEmptyTableField_Entity ($en) // [Entity en]
	{
		$dt = new DataTable();
		if (($en == NULL))
			$en = $this;
		$dt->TableName = $en->getEnMap()->getPhysicsTable();
		foreach ($en->getEnMap()->getAttrs() as $attr) 		{
			switch ($attr->getMyDataType()) {
				case $DataType->AppString:
					$dt->Columns->Add(new DataColumn($attr->getKey(), String,  TRUE ));
					break;
				case $DataType->AppInt:
					$dt->Columns->Add(new DataColumn($attr->getKey(), Integer,  TRUE ));
					break;
				case $DataType->AppFloat:
					$dt->Columns->Add(new DataColumn($attr->getKey(), Float,  TRUE ));
					break;
				case $DataType->AppBoolean:
					$dt->Columns->Add(new DataColumn($attr->getKey(), String,  TRUE ));
					break;
				case $DataType->AppDouble:
					$dt->Columns->Add(new DataColumn($attr->getKey(), Double,  TRUE ));
					break;
				case $DataType->AppMoney:
					$dt->Columns->Add(new DataColumn($attr->getKey(), Double,  TRUE ));
					break;
				case $DataType->AppDate:
					$dt->Columns->Add(new DataColumn($attr->getKey(), String,  TRUE ));
					break;
				case $DataType->AppDateTime:
					$dt->Columns->Add(new DataColumn($attr->getKey(), String,  TRUE ));
					break;
				default:
					throw new \RuntimeException("@bulider insert sql error: 没有这个数据类型");
			}
		}
		return $dt;
	}
	public function ToDataTableField ($tableName) // [String tableName]
	{
		$dt = $this->ToEmptyTableField();
		$dt->TableName = $tableName;
		if (($this->getRow()->containsKey("AtPara") ==  TRUE ))
		{
			$ap = $this->getatPara();
			foreach ($ap->getHisHT()->keySet() as $key) 			{
				if (($dt->Columns->contains($key) ==  TRUE ))
					continue;
				$dt->Columns->Add($key, System);
			}
		}
		$dr = $dt->NewRow();
		foreach ($this->getEnMap()->getAttrs() as $attr) 		{
			if (($attr->getMyDataType() == $DataType->AppBoolean))
			{
			/* match: String */
				if (($this->GetValIntByKey_String($attr->getKey()) == 1))
					$dr->setValue($attr->getKey(), "1");
				else
					$dr->setValue($attr->getKey(), "0");
				continue;
			}
			if ((($attr->getMyFieldType() == FieldType::$FK) || ($attr->getMyFieldType() == FieldType::$PKFK)))
			{
				$dr->setValue($attr->getKey(), $this->GetValByKey($attr->getKey())->trim());
				continue;
			}
			/* match: String */
			$obj = $this->GetValStrByKey_String($attr->getKey());
			if ((($obj . NULL) . $attr->getIsNum()))
				$obj = "0";
			$dr->setValue($attr->getKey(), $obj);
		}
		if (($this->getRow()->containsKey("AtPara") ==  TRUE ))
		{
			$ap = $this->getatPara();
			foreach ($ap->getHisHT()->keySet() as $key) 				$dr->setValue($key, $ap->getHisHT()->get($key));
		}
		$dt->Rows->add($dr);
		return $dt;
	}
	public function RunSQL_String ($sql) // [String sql]
	{
		$ps = new Paras();
		$ps->SQL = $sql;
		return $this->RunSQL_Paras($ps);
	}
	public function RunSQL_Paras ($ps) // [Paras ps]
	{
		return DBAccess::RunSQL($ps);
	}
	public function RunSQL_String_Paras ($sql, $paras) // [String sql, Paras paras]
	{
		return DBAccess::RunSQL($sql, $paras);
	}
	public function RunSQLReturnTable ($sql) // [String sql]
	{
		return DBAccess->RunSQLReturnTable($sql);
	}
	public function GenerNewNoByKey_String ($attrKey) // [String attrKey]
	{
		try 
		{
			$sql = NULL;
			$map = $this->getEnMap();
			$attr = $map->GetAttrByKey($attrKey);
			if (!$attr->getUIIsReadonly())
			{
				throw new \RuntimeException((("@�?要自动生成编号的�?(" . $attr->getKey()) . ")必须为只读�??"));
			}
			$field = $map->GetFieldByKey($attrKey);
			switch ($map->getEnDBUrl()->getDBType()) {
				case $MSSQL:
					$sql = ((("SELECT CONVERT(INT, MAX(CAST(" . $field) . " as int)) )+1 AS No FROM ") . $map->getPhysicsTable());
					break;
				case $Oracle:
					$sql = ((("SELECT MAX(" . $field) . ") +1 AS No FROM ") . $map->getPhysicsTable());
					break;
				case $MySQL:
					$sql = ((("SELECT CONVERT(MAX(CAST(" . $field) . " AS SIGNED INTEGER)),SIGNED) +1 AS No FROM ") . $map->getPhysicsTable());
					break;
				case $Informix:
					$sql = ((("SELECT MAX(" . $field) . ") +1 AS No FROM ") . $map->getPhysicsTable());
					break;
				case $Access:
					$sql = ((("SELECT MAX( [" . $field) . "]) +1 AS  No FROM ") . $map->getPhysicsTable());
					break;
				default:
					throw new \RuntimeException("error");
			}
			$str = (new Integer(DBAccess->RunSQLReturnValInt($sql, 1)));
			if (($str->equals("0") || $str->equals("")))
			{
				$str = "1";
			}
			return $StringUtils->leftPad($str, $Integer->parseInt($map->getCodeStruct()), "0");
		}
		catch (\RuntimeException $ex)
		{
			$this->CheckPhysicsTable();
			throw $ex;
		}
	}
	public function GenerNewNoByKey_I_String_String_String ($nolength, $attrKey, $attrGroupKey, $attrGroupVal) // [int nolength, String attrKey, String attrGroupKey, String attrGroupVal]
	{
		if ((($attrGroupKey . NULL) . ($attrGroupVal . NULL)))
		{
			throw new \RuntimeException("@分组字段attrGroupKey attrGroupVal 不能为空");
		}
		$map = $this->getEnMap();
		$ps = new Paras();
		$sql = "";
		$field = $map->GetFieldByKey($attrKey);
		switch ($map->getEnDBUrl()->getDBType()) {
			case $MSSQL:
				$sql = (((((((("SELECT CONVERT(bigint, MAX([" . $field) . "]))+1 AS Num FROM ") . $map->getPhysicsTable()) . " WHERE ") . $attrGroupKey) . "='") . $attrGroupVal) . "'");
				break;
			case $Oracle:
				$ps->Add("groupKey", $attrGroupKey);
				$ps->Add("groupVal", $attrGroupVal);
				$ps->Add("f", $attrKey);
				$sql = (((((("SELECT MAX( :f )+1 AS No FROM " . $map->getPhysicsTable()) . " WHERE ") . $this->getHisDBVarStr()) . "groupKey=") . $this->getHisDBVarStr()) . "groupVal ");
				break;
			case $Informix:
				$sql = (((((("SELECT MAX( :f )+1 AS No FROM " . $map->getPhysicsTable()) . " WHERE ") . $this->getHisDBVarStr()) . "groupKey=") . $this->getHisDBVarStr()) . "groupVal ");
				break;
			case $MySQL:
				$sql = (((((((("SELECT MAX(" . $field) . ") +1 AS Num FROM ") . $map->getPhysicsTable()) . " WHERE ") . $attrGroupKey) . "='") . $attrGroupVal) . "'");
				break;
			case $Access:
				$sql = (((((((("SELECT MAX([" . $field) . "]) +1 AS Num FROM ") . $map->getPhysicsTable()) . " WHERE ") . $attrGroupKey) . "='") . $attrGroupVal) . "'");
				break;
			default:
				throw new \RuntimeException("error");
		}
		$dt = DBAccess->RunSQLReturnTable($sql, $ps);
		$str = "1";
		if (($dt->Rows->size() != 0))
		{
			if (($dt->Rows->get(0)->getValue(0) == NULL))
			{
				$str = "1";
			}
			else
			{
				$str = $dt->Rows->get(0)->getValue(0);
			}
		}
		return $StringUtils->leftPad($str, $nolength, '0');
	}
	public function GenerNewNoByKey_String_String_String ($attrKey, $attrGroupKey, $attrGroupVal) // [String attrKey, String attrGroupKey, String attrGroupVal]
	{
			/* match: I_String_String_String */
		return $this->GenerNewNoByKey_I_String_String_String($Integer->parseInt($this->getEnMap()->getCodeStruct()), $attrKey, $attrGroupKey, $attrGroupVal);
	}
	public function GenerNewNoByKey_String_String_String_Object_Object ($attrKey, $attrGroupKey1, $attrGroupKey2, $attrGroupVal1, $attrGroupVal2) // [String attrKey, String attrGroupKey1, String attrGroupKey2, Object attrGroupVal1, Object attrGroupVal2]
	{
		$f = $this->getEnMap()->GetFieldByKey($attrKey);
		$ps = new Paras();
		$sql = "";
		switch ($this->getEnMap()->getEnDBUrl()->getDBType()) {
			case $Oracle:
			case $Informix:
				$sql = ((("SELECT   MAX(" . $f) . ") +1 AS No FROM ") . $this->getEnMap()->getPhysicsTable());
				break;
			case $MSSQL:
				$sql = (((((((((((("SELECT CONVERT(INT, MAX(" . $this->getEnMap()->GetFieldByKey($attrKey)) . ") )+1 AS No FROM ") . $this->getEnMap()->getPhysicsTable()) . " WHERE ") . $this->getEnMap()->GetFieldByKey($attrGroupKey1)) . "='") . $attrGroupVal1) . "' AND ") . $this->getEnMap()->GetFieldByKey($attrGroupKey2)) . "='") . $attrGroupVal2) . "'");
				break;
			case $Access:
				$sql = (((((((((((("SELECT CONVERT(INT, MAX(" . $this->getEnMap()->GetFieldByKey($attrKey)) . ") )+1 AS No FROM ") . $this->getEnMap()->getPhysicsTable()) . " WHERE ") . $this->getEnMap()->GetFieldByKey($attrGroupKey1)) . "='") . $attrGroupVal1) . "' AND ") . $this->getEnMap()->GetFieldByKey($attrGroupKey2)) . "='") . $attrGroupVal2) . "'");
				break;
			default:
				break;
		}
		$dt = DBAccess->RunSQLReturnTable($sql, $ps);
		$str = "1";
		if (($dt->Rows->size() != 0))
		{
			$str = $dt->Rows->get(0)->getValue(0);
		}
		return $StringUtils->leftPad($str, $Integer->parseInt($this->getEnMap()->getCodeStruct()), '0');
	}
	public static function constructor__ () 
	{
		$me = new self();
		$me->__init();
		return $me;
	}
	protected function DoOrderUp_String_String_String ($groupKeyAttr, $groupKeyVal, $idxAttr) // [String groupKeyAttr, String groupKeyVal, String idxAttr]
	{
		$pkval = $this->getPKVal();
		$pk = $this->getPK();
		$table = $this->getEnMap()->getPhysicsTable();
		$sql = ((((((((((("SELECT " . $pk) . ",") . $idxAttr) . " FROM ") . $table) . " WHERE ") . $groupKeyAttr) . "='") . $groupKeyVal) . "' ORDER BY ") . $idxAttr);
		$dt =DBAccess->RunSQLReturnTable($sql);
		$idx = 0;
		$beforeNo = "";
		$myNo = "";
		$isMeet =  FALSE ;
		foreach ($dt->Rows as $dr) 		{
			++$idx;
			$myNo = $dr->getValue($pk);
			if ($pkval->equals($myNo))
			{
				$isMeet =  TRUE ;
				break;
			}
			if (!$isMeet)
			{
				$beforeNo = $myNo;
			}
			DBAccess::RunSQL((((((((((("UPDATE " . $table) . " SET ") . $idxAttr) . "=") . $idx) . " WHERE ") . $pk) . "='") . $myNo) . "'"));
		}
		DBAccess::RunSQL((((((((((("UPDATE " . $table) . " SET ") . $idxAttr) . "=") . $idxAttr) . "+1 WHERE ") . $pk) . "='") . $beforeNo) . "'"));
		DBAccess::RunSQL((((((((((("UPDATE " . $table) . " SET ") . $idxAttr) . "=") . $idxAttr) . "-1 WHERE ") . $pk) . "='") . $pkval) . "'"));
	}
	protected function DoOrderUp_String_String_String_String_String ($groupKeyAttr, $groupKeyVal, $gKey2, $gVal2, $idxAttr) // [String groupKeyAttr, String groupKeyVal, String gKey2, String gVal2, String idxAttr]
	{
		$pkval = $this->getPKVal();
		$pk = $this->getPK();
		$table = $this->getEnMap()->getPhysicsTable();
		$sql = ((((((((((((((("SELECT " . $pk) . ",") . $idxAttr) . " FROM ") . $table) . " WHERE (") . $groupKeyAttr) . "='") . $groupKeyVal) . "' AND ") . $gKey2) . "='") . $gVal2) . "') ORDER BY ") . $idxAttr);
		$dt =DBAccess->RunSQLReturnTable($sql);
		$idx = 0;
		$beforeNo = "";
		$myNo = "";
		$isMeet =  FALSE ;
		foreach ($dt->Rows as $dr) 		{
			++$idx;
			$myNo = $dr->getValue($pk);
			if ($pkval->equals($myNo))
			{
				$isMeet =  TRUE ;
				break;
			}
			if (!$isMeet)
			{
				$beforeNo = $myNo;
			}
			DBAccess::RunSQL((((((((((((((((((("UPDATE " . $table) . " SET ") . $idxAttr) . "=") . $idx) . " WHERE ") . $pk) . "='") . $myNo) . "'  AND  (") . $groupKeyAttr) . "='") . $groupKeyVal) . "' AND ") . $gKey2) . "='") . $gVal2) . "') "));
		}
		DBAccess::RunSQL((((((((((((((((((("UPDATE " . $table) . " SET ") . $idxAttr) . "=") . $idxAttr) . "+1 WHERE ") . $pk) . "='") . $beforeNo) . "'  AND  (") . $groupKeyAttr) . "='") . $groupKeyVal) . "' AND ") . $gKey2) . "='") . $gVal2) . "')"));
		DBAccess::RunSQL((((((((((((((((((("UPDATE " . $table) . " SET ") . $idxAttr) . "=") . $idxAttr) . "-1 WHERE ") . $pk) . "='") . $pkval) . "'  AND   (") . $groupKeyAttr) . "='") . $groupKeyVal) . "' AND ") . $gKey2) . "='") . $gVal2) . "')"));
	}
	protected function DoOrderDown_String_String_String ($groupKeyAttr, $groupKeyVal, $idxAttr) // [String groupKeyAttr, String groupKeyVal, String idxAttr]
	{
		$pkval = $this->getPKVal();
		$pk = $this->getPK();
		$table = $this->getEnMap()->getPhysicsTable();
		$sql = ((((((((((("SELECT " . $pk) . " ,") . $idxAttr) . " FROM ") . $table) . " WHERE ") . $groupKeyAttr) . "='") . $groupKeyVal) . "' order by ") . $idxAttr);
		$dt = DBAccess->RunSQLReturnTable($sql);
		$idx = 0;
		$nextNo = "";
		$myNo = "";
		$isMeet =  FALSE ;
		foreach ($dt->Rows as $dr) 		{
			$myNo = $dr->getValue($pk);
			if ($isMeet)
			{
				$nextNo = $myNo;
				$isMeet =  FALSE ;
			}
			++$idx;
			if ($pkval->equals($myNo))
			{
				$isMeet =  TRUE ;
			}
			DBAccess::RunSQL((((((((((("UPDATE " . $table) . " SET ") . $idxAttr) . "=") . $idx) . " WHERE ") . $pk) . "='") . $myNo) . "'"));
		}
		DBAccess::RunSQL((((((((((("UPDATE  " . $table) . " SET ") . $idxAttr) . "=") . $idxAttr) . "-1 WHERE ") . $pk) . "='") . $nextNo) . "'"));
		DBAccess::RunSQL((((((((((("UPDATE  " . $table) . " SET ") . $idxAttr) . "=") . $idxAttr) . "+1 WHERE ") . $pk) . "='") . $pkval) . "'"));
	}
	protected function DoOrderDown_String_String_String_String_String ($groupKeyAttr, $groupKeyVal, $gKeyAttr2, $gKeyVal2, $idxAttr) // [String groupKeyAttr, String groupKeyVal, String gKeyAttr2, String gKeyVal2, String idxAttr]
	{
		$pkval = $this->getPKVal();
		$pk = $this->getPK();
		$table = $this->getEnMap()->getPhysicsTable();
		$sql = ((((((((((((((("SELECT " . $pk) . " ,") . $idxAttr) . " FROM ") . $table) . " WHERE (") . $groupKeyAttr) . "='") . $groupKeyVal) . "' AND ") . $gKeyAttr2) . "='") . $gKeyVal2) . "' ) order by ") . $idxAttr);
		$dt = DBAccess->RunSQLReturnTable($sql);
		$idx = 0;
		$nextNo = "";
		$myNo = "";
		$isMeet =  FALSE ;
		foreach ($dt->Rows as $dr) 		{
			$myNo = $dr->getValue($pk);
			if ($isMeet)
			{
				$nextNo = $myNo;
				$isMeet =  FALSE ;
			}
			++$idx;
			if ($pkval->equals($myNo))
			{
				$isMeet =  TRUE ;
			}
			DBAccess::RunSQL((((((((((((((((((("UPDATE " . $table) . " SET ") . $idxAttr) . "=") . $idx) . " WHERE ") . $pk) . "='") . $myNo) . "' AND  (") . $groupKeyAttr) . "='") . $groupKeyVal) . "' AND ") . $gKeyAttr2) . "='") . $gKeyVal2) . "' ) "));
		}
		DBAccess::RunSQL((((((((((((((((((("UPDATE  " . $table) . " SET ") . $idxAttr) . "=") . $idxAttr) . "-1 WHERE ") . $pk) . "='") . $nextNo) . "' AND (") . $groupKeyAttr) . "='") . $groupKeyVal) . "' AND ") . $gKeyAttr2) . "='") . $gKeyVal2) . "' )"));
		DBAccess::RunSQL((((((((((((((((((("UPDATE  " . $table) . " SET ") . $idxAttr) . "=") . $idxAttr) . "+1 WHERE ") . $pk) . "='") . $pkval) . "' AND (") . $groupKeyAttr) . "='") . $groupKeyVal) . "' AND ") . $gKeyAttr2) . "='") . $gKeyVal2) . "' )"));
	}
	public function DirectUpdate () 
	{
		return EntityDBAccess::Update($this, NULL);
	}
	public function DirectInsert () 
	{
		try 
		{
			/* match: String_Paras */
			return $this->RunSQL_String_Paras($this->getSQLCash()->Insert, SqlBuilder::GenerParas($this, NULL));
		}
		catch (\RuntimeException $ex)
		{
			$this->roll();
			if ($SystemConfig->getIsDebug())
			{
				try 
				{
					$this->CheckPhysicsTable();
				}
				catch (Exception $ex1)
				{
					throw new \RuntimeException((($ex->getMessage() . " == ") . $ex1->getMessage()));
				}
			}
			throw $ex;
		}
	}
	public function DirectDelete () 
	{
		DBAccess::RunSQL($this->getSQLCash()->Delete, SqlBuilder::GenerParasPK($this));
	}
	public function DirectSave () 
	{
		if ($this->getIsExits())
		{
			$this->DirectUpdate();
		}
		else
		{
			$this->DirectInsert();
		}
	}
	public function RetrieveByAttrAnd ($attr1, $val1, $attr2, $val2) // [String attr1, Object val1, String attr2, Object val2]
	{
		$qo = QueryObject::constructor__Entity($this);
		$qo->AddWhere_String_Object($attr1, $val1);
		$qo->addAnd();
		$qo->AddWhere_String_Object($attr2, $val2);
		if (($qo->DoQuery() >= 1))
		{
			return  TRUE ;
		}
		else
		{
			return  FALSE ;
		}
	}
	public function RetrieveByAttrOr ($attr1, $val1, $attr2, $val2) // [String attr1, Object val1, String attr2, Object val2]
	{
		$qo = QueryObject::constructor__Entity($this);
		$qo->AddWhere_String_Object($attr1, $val1);
		$qo->addOr();
		$qo->AddWhere_String_Object($attr2, $val2);
		if (($qo->DoQuery() == 1))
		{
			return  TRUE ;
		}
		else
		{
			return  FALSE ;
		}
	}
	public function RetrieveByAttr ($attr, $val) // [String attr, Object val]
	{
		$qo = QueryObject::constructor__Entity($this);
		$qo->AddWhere_String_Object($attr, $val);
		if (($qo->DoQuery() == 1))
		{
			return  TRUE ;
		}
		else
		{
			return  FALSE ;
		}
	}
	public function RetrieveFromDBSources () 
	{
		try 
		{
			return DBAccess->RunSQLReturnResultSet($this->getSQLCash()->Select, SqlBuilder::GenerParasPK($this), $this, $this->getEnMap()->getAttrs());
		}
		catch (\Exception $e)
		{
			try 
			{
				$this->CheckPhysicsTable();
			}
			catch (Exception $e1)
			{
				$e1->printStackTrace();
			}
			return DBAccess->RunSQLReturnResultSet($this->getSQLCash()->Select, SqlBuilder::GenerParasPK($this), $this, $this->getEnMap()->getAttrs());
		}
	}
	public function Retrieve_String_Object ($key, $val) // [String key, Object val]
	{
		$qo = QueryObject::constructor__Entity($this);
		$qo->AddWhere_String_Object($key, $val);
		return $qo->DoQuery();
	}
	public function Retrieve_String_Object_String_Object ($key1, $val1, $key2, $val2) // [String key1, Object val1, String key2, Object val2]
	{
		$qo = QueryObject::constructor__Entity($this);
		$qo->AddWhere_String_Object($key1, $val1);
		$qo->addAnd();
		$qo->AddWhere_String_Object($key2, $val2);
		return $qo->DoQuery();
	}
	public function Retrieve_String_Object_String_Object_String_Object ($key1, $val1, $key2, $val2, $key3, $val3) // [String key1, Object val1, String key2, Object val2, String key3, Object val3]
	{
		$qo = QueryObject::constructor__Entity($this);
		$qo->AddWhere_String_Object($key1, $val1);
		$qo->addAnd();
		$qo->AddWhere_String_Object($key2, $val2);
		$qo->addAnd();
		$qo->AddWhere_String_Object($key3, $val3);
		return $qo->DoQuery();
	}
	public function Retrieve_String_Object_String_Object_String_Object_String_Object ($key1, $val1, $key2, $val2, $key3, $val3, $key4, $val4) // [String key1, Object val1, String key2, Object val2, String key3, Object val3, String key4, Object val4]
	{
		$qo = QueryObject::constructor__Entity($this);
		$qo->AddWhere_String_Object($key1, $val1);
		$qo->addAnd();
		$qo->AddWhere_String_Object($key2, $val2);
		$qo->addAnd();
		$qo->AddWhere_String_Object($key3, $val3);
		$qo->addAnd();
		$qo->AddWhere_String_Object($key4, $val4);
		return $qo->DoQuery();
	}
	public function Retrieve () 
	{
		if (($this->getEnMap()->getDepositaryOfEntity() == $Depositary->Application))
		{
			$row =Cash2019->GetRow($this, $this->getPKVal());
			if (($row != NULL))
			{
				$this->setRow($row);
				return 1;
			}
		}
		try 
		{
			$i = DBAccess->RunSQLReturnResultSet($this->getSQLCash()->Select, SqlBuilder::GenerParasPK($this), $this, $this->getEnMap()->getAttrs());
			if (($i > 0))
			{
				if (($this->getEnMap()->getDepositaryOfEntity() == $Depositary->Application))
				{
					Cash2019->PutRow($this, $this->getPKVal(), $this->getRow());
				}
				return $i;
			}
		}
		catch (\RuntimeException $ex)
		{
			$msg = ( (($ex->getMessage() == NULL)) ? "" : $ex->getMessage() );
			if (($msg->contains("无效") || $msg->contains("field list")))
			{
				try 
				{
					$this->CheckPhysicsTable();
					if ((DBAccess->IsExits($this->getEnMap()->getPhysicsTable()) ==  TRUE ))
						return $this->RetrieveFromDBSources();
				}
				catch (Exception $e)
				{
					$e->printStackTrace();
				}
			}
			throw new \RuntimeException((((($msg . "@在Entity(") . $this) . ")查询期间出现错误@") . $ex->getStackTrace()));
		}
		$msg = "";
		$pk = $this->getPK();
		if ($pk->equals("OID"))
		{
			/* match: String */
			$msg += (("[ 主键=OID �?=" . $this->GetValStrByKey_String("OID")) . " ]");
		}
		else
			if ($pk->equals("No"))
			{
			/* match: String */
				$msg += (("[ 主键=No �?=" . $this->GetValStrByKey_String("No")) . " ]");
			}
			else
				if ($pk->equals("MyPK"))
				{
			/* match: String */
					$msg += (("[ 主键=MyPK �?=" . $this->GetValStrByKey_String("MyPK")) . " ]");
				}
				else
					if ($pk->equals("NodeID"))
					{
			/* match: String */
						$msg += (("[ 主键=NodeID �?=" . $this->GetValStrByKey_String("NodeID")) . " ]");
					}
					else
						if ($pk->equals("WorkID"))
						{
			/* match: String */
							$msg += (("[ 主键=WorkID �?=" . $this->GetValStrByKey_String("WorkID")) . " ]");
						}
						else
						{
							$ht = $this->getPKVals();
							$keys = $ht->keySet();
							foreach ($keys as $key) 							{
								$msg += (((("[ 主键=" . $key) . " �?=") . $ht->get($key)) . " ]");
							}
							throw new \RuntimeException(((((((((("@没有[" . $this->getEnMap()->getEnDesc()) . "  ") . $this->getEnMap()->getPhysicsTable()) . ", 类[") . $this) . "], 物理表[") . $this->getEnMap()->getPhysicsTable()) . "] 实例�?") . $msg));
						}
		return 0;
	}
	public function Retrieve_Old () 
	{
		try 
		{
			/* match: Entity_String_Paras */
			$num = EntityDBAccess->Retrieve_Entity_String_Paras($this, $this->getSQLCash()->Select, SqlBuilder::GenerParasPK($this));
			if (($num <= 0))
			{
				$msg = "";
				if ($this->getPK()->equals("OID"))
				{
			/* match: String */
					$msg += (("[ 主键=OID �?=" . $this->GetValStrByKey_String("OID")) . " ]");
				}
				else
					if ($this->getPK()->equals("No"))
					{
			/* match: String */
						$msg += (("[ 主键=No �?=" . $this->GetValStrByKey_String("No")) . " ]");
					}
					else
						if ($this->getPK()->equals("MyPK"))
						{
			/* match: String */
							$msg += (("[ 主键=MyPK �?=" . $this->GetValStrByKey_String("MyPK")) . " ]");
						}
						else
							if ($this->getPK()->equals("ID"))
							{
			/* match: String */
								$msg += (("[ 主键=ID �?=" . $this->GetValStrByKey_String("ID")) . " ]");
							}
							else
							{
								$ht = $this->getPKVals();
								$keys = $ht->keySet();
								foreach ($keys as $key) 								{
									$msg += (((("[ 主键=" . $key) . " �?=") . $ht->get($key)) . " ]");
								}
							}
				$Log->DefaultLogWriteLine($LogType->Error, (((((((((("@没有[" . $this->getEnMap()->getEnDesc()) . "  ") . $this->getEnMap()->getPhysicsTable()) . ", 类[") . $this) . "], 物理表[") . $this->getEnMap()->getPhysicsTable()) . "] 实例。PK = ") . $this->GetValByKey($this->getPK())) . $msg));
			}
			return 1;
		}
		catch (\RuntimeException $ex)
		{
			$msg = ( (($ex->getMessage() == NULL)) ? "" : $ex->getMessage() );
			if (($msg->contains("无效") || $msg->contains("field list")))
			{
				try 
				{
					$this->CheckPhysicsTable();
					if ((DBAccess->IsExits($this->getEnMap()->getPhysicsTable()) ==  FALSE ))
						return $this->Retrieve();
				}
				catch (Exception $e)
				{
					$e->printStackTrace();
				}
			}
			throw new \RuntimeException((((($msg . "@在Entity(") . $this) . ")查询期间出现错误@") . $ex->getStackTrace()));
		}
	}
	public function getIsExits () 
	{
		try 
		{
			if ($this->getPK()->contains(","))
			{
				$attrs = $this->getEnMap()->getAttrs();
				$qo = QueryObject::constructor__Entity($this);
				$pks = $this->getPK()->split("[,]", -1);
				$isNeedAddAnd =  FALSE ;
				foreach ($pks as $pk) 				{
					if (is_null($pk) || $pk == '')
					{
						continue;
					}
					if ($isNeedAddAnd)
					{
						$qo->addAnd();
					}
					else
					{
						$isNeedAddAnd =  TRUE ;
					}
					$attr = $attrs->GetAttrByKey($pk);
					switch ($attr->getMyDataType()) {
						case $DataType->AppBoolean:
						case $DataType->AppInt:
			/* match: String */
							$qo->AddWhere_String_I($pk, $this->GetValIntByKey_String($attr->getKey()));
							break;
						case $DataType->AppDouble:
						case $DataType->AppMoney:
						case $DataType->AppRate:
			/* match: String */
							$qo->AddWhere($pk, $this->GetValDecimalByKey_String($attr->getKey()));
							break;
						default:
			/* match: String */
							$qo->AddWhere_String_String($pk, $this->GetValStringByKey_String($attr->getKey()));
							break;
					}
				}
				if (($qo->DoQueryToTable()->Rows->size() == 0))
				{
					return  FALSE ;
				}
				return  TRUE ;
			}
			$obj = $this->getPKVal();
			if ((($obj == NULL) || $obj->equals("")))
			{
				return  FALSE ;
			}
			if ($this->getIsOIDEntity())
			{
				if ($obj->equals("0"))
				{
					return  FALSE ;
				}
			}
			$selectSQL = (((("SELECT count( " . $this->getPK()) . ") as Num FROM ") . $this->getEnMap()->getPhysicsTable()) . " WHERE ");
			switch ($SystemConfig->getAppCenterDBType()) {
				case $MSSQL:
					$selectSQL += SqlBuilder::GetKeyConditionOfMS($this);
					break;
				case $Oracle:
					$selectSQL += SqlBuilder::GetKeyConditionOfOraForPara($this);
					break;
				case $Informix:
					$selectSQL += SqlBuilder::GetKeyConditionOfInformixForPara($this);
					break;
				case $MySQL:
					$selectSQL += SqlBuilder::GetKeyConditionOfMySQL($this);
					break;
				case $Access:
					$selectSQL += SqlBuilder::GetKeyConditionOfOLE($this);
					break;
				default:
					throw new \RuntimeException(("@没有设计到�??" . $this->getEnMap()->getEnDBUrl()->getDBUrlType()));
			}
			$ps = SqlBuilder::GenerParasPK($this);
			$ps->SQL = $selectSQL;
			$val = DBAccess->RunSQLReturnValInt($ps);
			if (($val == 0))
				return  FALSE ;
			return  TRUE ;
		}
		catch (\RuntimeException $ex)
		{
			$this->CheckPhysicsTable();
			throw $ex;
		}
	}
	public function RetrieveNotSetValues () 
	{
		return $this->RunSQLReturnTable(SqlBuilder::Retrieve($this));
	}
	public function IsExit_String_Object ($pk, $val) // [String pk, Object val]
	{
		if ($pk->equals("OID"))
		{
			if (($Integer->parseInt($val) == 0))
			{
				return  FALSE ;
			}
			else
			{
				return  TRUE ;
			}
		}
		$ps = new Paras();
		$ps->SQL = (((((((("SELECT COUNT(" . $pk) . ") FROM ") . $this->getEnMap()->getPhysicsTable()) . " WHERE ") . $pk) . "=") . $ps->getDBStr()) . "PK");
		$ps->Add("PK", $val);
		$num = DBAccess->RunSQLReturnValInt($ps);
		if (($num == 0))
			return  FALSE ;
		return  TRUE ;
	}
	public function IsExit_String_Object_String_Object ($pk1, $val1, $pk2, $val2) // [String pk1, Object val1, String pk2, Object val2]
	{
		$ps = new Paras();
		$ps->SQL = (((((((((((("SELECT COUNT(" . $pk1) . ") as Num FROM ") . $this->getEnMap()->getPhysicsTable()) . " WHERE ") . $pk1) . "=") . $ps->getDBStr()) . "PK1 AND ") . $pk2) . "=") . $ps->getDBStr()) . "PK2");
		$ps->Add("PK1", $val1);
		$ps->Add("PK2", $val2);
		$num = DBAccess->RunSQLReturnValInt($ps);
		if (($num == 0))
			return  FALSE ;
		return  TRUE ;
	}
	public function IsExit_String_Object_String_Object_String_Object ($pk1, $val1, $pk2, $val2, $pk3, $val3) // [String pk1, Object val1, String pk2, Object val2, String pk3, Object val3]
	{
		$ps = new Paras();
		$ps->SQL = (((((((((((((((("SELECT COUNT(" . $pk1) . ") as Num FROM ") . $this->getEnMap()->getPhysicsTable()) . " WHERE ") . $pk1) . "=") . $ps->getDBStr()) . "PK1 AND ") . $pk2) . "=") . $ps->getDBStr()) . "PK2 AND  ") . $pk3) . "=") . $ps->getDBStr()) . "PK3");
		$ps->Add("PK1", $val1);
		$ps->Add("PK2", $val2);
		$ps->Add("PK3", $val3);
		$num = DBAccess->RunSQLReturnValInt($ps);
		if (($num == 0))
			return  FALSE ;
		return  TRUE ;
	}
	protected function beforeDelete () 
	{
		return  TRUE ;
	}
	public function DeleteDataAndCash () 
	{
		$this->Delete();
		$this->DeleteFromCash();
	}
	public function DeleteFromCash () 
	{
		$CashEntity->Delete($this, $this->getPKVal());
		$this->getRow()->clear();
	}
	public function Delete () 
	{
		if (!$this->beforeDelete())
		{
			return 0;
		}
		$i = 0;
		try 
		{
			$i = DBAccess::RunSQL($this->getSQLCash()->Delete, SqlBuilder::GenerParasPK($this));
		}
		catch (\RuntimeException $ex)
		{
			$Log->DebugWriteInfo($ex->getMessage());
			throw $ex;
		}
		if (($this->getEnMap()->getDepositaryOfEntity() == $Depositary->Application))
			$Cash2019->DeleteRow($this, $this->getPKVal());
		$this->afterDelete();
		return $i;
	}
	public function Delete_String_Object ($attr, $val) // [String attr, Object val]
	{
		$ps = new Paras();
		$ps->Add($attr, $val);
		return DBAccess::RunSQL((((((("DELETE FROM " . $this->getEnMap()->getPhysicsTable()) . " WHERE ") . $this->getEnMap()->GetAttrByKey($attr)->getField()) . " =") . $this->getHisDBVarStr()) . $attr), $ps);
	}
	public function Delete_String_Object_String_Object ($attr1, $val1, $attr2, $val2) // [String attr1, Object val1, String attr2, Object val2]
	{
		$ps = new Paras();
		$ps->Add($attr1, $val1);
		$ps->Add($attr2, $val2);
		return DBAccess::RunSQL(((((((((((("DELETE FROM " . $this->getEnMap()->getPhysicsTable()) . " WHERE ") . $attr1) . " =") . $this->getHisDBVarStr()) . $attr1) . " AND ") . $attr2) . " =") . $this->getHisDBVarStr()) . $attr2), $ps);
	}
	public function Delete_String_Object_String_Object_String_Object ($attr1, $val1, $attr2, $val2, $attr3, $val3) // [String attr1, Object val1, String attr2, Object val2, String attr3, Object val3]
	{
		$ps = new Paras();
		$ps->Add($attr1, $val1);
		$ps->Add($attr2, $val2);
		$ps->Add($attr3, $val3);
		return DBAccess::RunSQL((((((((((((((((("DELETE FROM " . $this->getEnMap()->getPhysicsTable()) . " WHERE ") . $attr1) . " =") . $this->getHisDBVarStr()) . $attr1) . " AND ") . $attr2) . " =") . $this->getHisDBVarStr()) . $attr2) . " AND ") . $attr3) . " =") . $this->getHisDBVarStr()) . $attr3), $ps);
	}
	public function Delete_String_Object_String_Object_String_Object_String_Object ($attr1, $val1, $attr2, $val2, $attr3, $val3, $attr4, $val4) // [String attr1, Object val1, String attr2, Object val2, String attr3, Object val3, String attr4, Object val4]
	{
		$ps = new Paras();
		$ps->Add($attr1, $val1);
		$ps->Add($attr2, $val2);
		$ps->Add($attr3, $val3);
		$ps->Add($attr4, $val4);
		return DBAccess::RunSQL(((((((((((((((((((((("DELETE FROM " . $this->getEnMap()->getPhysicsTable()) . " WHERE ") . $attr1) . " =") . $this->getHisDBVarStr()) . $attr1) . " AND ") . $attr2) . " =") . $this->getHisDBVarStr()) . $attr2) . " AND ") . $attr3) . " =") . $this->getHisDBVarStr()) . $attr3) . " AND ") . $attr4) . " =") . $this->getHisDBVarStr()) . $attr4), $ps);
	}
	protected function afterDelete () 
	{
		return ;
	}
	protected function getAtPara () 
	{
		$tempVar = $this->getRow()->GetValByKey("_ATObj_");
		$at = (( (($tempVar instanceof AtPara)) ? $tempVar : NULL ));
		if (($at != NULL))
		{
			return $at;
		}
		try 
		{
			/* match: String */
			$atParaStr = $this->GetValStringByKey_String("AtPara");
			if (is_null($atParaStr) || $atParaStr == '')
			{
				$this->InitParaFields();
			/* match: String */
				$atParaStr = $this->GetValStringByKey_String("AtPara");
				if (is_null($atParaStr) || $atParaStr == '')
				{
					$atParaStr = "";
				}
				$at = new AtPara($atParaStr);
				$this->SetValByKey("_ATObj_", $at);
				return $at;
			}
			$at = new AtPara($atParaStr);
			$this->SetValByKey("_ATObj_", $at);
			return $at;
		}
		catch (\RuntimeException $ex)
		{
			throw new \RuntimeException(((("@获取参数AtPara时出现异�?" . $ex->getMessage()) . "，可能是您没有加入约定的参数字段AtPara. ") . $ex->getMessage()));
		}
	}
	abstract function InitParaFields (); 
	public function GetParaString_String ($key) // [String key]
	{
		return $this->getAtPara()->GetValStrByKey($key);
	}
	public function GetParaString_String_String ($key, $isNullAsVal) // [String key, String isNullAsVal]
	{
		$str = $this->getAtPara()->GetValStrByKey($key);
		if (is_null($str) || $str == '')
		{
			return $isNullAsVal;
		}
		return $str;
	}
	public function GetParaInt_String ($key) // [String key]
	{
		return $this->getAtPara()->GetValIntByKey($key);
	}
	public function GetParaInt_String_I ($key, $isNullAsVal) // [String key, int isNullAsVal]
	{
		return $this->getAtPara()->GetValIntByKey($key, $isNullAsVal);
	}
	public function GetParaFloat ($key) // [String key]
	{
		return $this->getAtPara()->GetValFloatByKey($key);
	}
	public function GetParaBoolen_String ($key) // [String key]
	{
		return $this->getAtPara()->GetValBoolenByKey($key);
	}
	public function GetParaBoolen_String_b ($key, $IsNullAsVal) // [String key, boolean IsNullAsVal]
	{
		return $this->getAtPara()->GetValBoolenByKey($key, $IsNullAsVal);
	}
	public function SetPara_String_String ($key, $obj) // [String key, String obj]
	{
		if (($this->getAtPara() != NULL))
		{
			$this->getRow()->remove("_ATObj_");
		}
			/* match: String */
		$atParaStr = $this->GetValStringByKey_String("AtPara");
		if (!$atParaStr->contains((("@" . $key) . "=")))
		{
			$atParaStr += ((("@" . $key) . "=") . $obj);
			$this->SetValByKey_String_String("AtPara", $atParaStr);
			return ;
		}
		else
		{
			$at = new AtPara($atParaStr);
			$at->SetVal($key, $obj);
			$this->SetValByKey_String_F("AtPara", $at->GenerAtParaStrs());
			return ;
		}
	}
	public function SetPara_String_I ($key, $obj) // [String key, int obj]
	{
		$this->SetPara_String_F($key, (new Integer($obj)));
	}
	public function SetPara_String_F ($key, $obj) // [String key, float obj]
	{
		$this->SetPara_String_F($key, (new Float($obj)));
	}
	public function SetPara_String_b ($key, $obj) // [String key, boolean obj]
	{
		if (!$obj)
		{
			$this->SetPara_String_String($key, "0");
		}
		else
		{
			$this->SetPara_String_String($key, "1");
		}
	}
	public function GetRefObject ($key) // [String key]
	{
		return $this->getRow()->GetValByKey(("_" . $key));
	}
	public function SetRefObject ($key, $obj) // [String key, Object obj]
	{
		if (($obj == NULL))
		{
			return ;
		}
		$this->getRow()->SetValByKey(("_" . $key), $obj);
	}
	protected function beforeInsert () 
	{
		return  TRUE ;
	}
	protected function roll () 
	{
		return  TRUE ;
	}
	public function Insert () 
	{
		if (!$this->beforeInsert())
		{
			return 0;
		}
		if (!$this->beforeUpdateInsertAction())
		{
			return 0;
		}
		$i = 0;
		try 
		{
			$i = $this->DirectInsert();
		}
		catch (\RuntimeException $ex)
		{
			$this->CheckPhysicsTable();
			throw $ex;
		}
		$this->afterInsert();
		$this->afterInsertUpdateAction();
		if (($this->getEnMap()->getDepositaryOfEntity() == $Depositary->Application))
			$Cash2019->PutRow($this, $this->getPKVal(), $this->getRow());
		return $i;
	}
	protected function afterInsert () 
	{
		if (($this->getEnMap()->IsEnableVer ==  FALSE ))
			return ;
		$enName = $this;
		$rdt =DataType->getCurrentDataTime();
		$ver = new EnVer();
		$ver->setMyPK((($enName . "_") . $this->getPKVal()));
		if (($ver->RetrieveFromDBSources() == 0))
		{
			$ver->setNo($enName);
			$ver->setPKValue($this->getPKVal());
			$ver->setName($this->getEnMap()->getEnDesc());
		}
		else
		{
			$ver->setEVer(($ver->getEVer() + 1));
		}
		$ver->setRDT($rdt);
		$ver->setRec($WebUser->getName());
		$ver->Save();
		$attrs = $this->getEnMap()->getAttrs();
		foreach ($attrs->ToJavaList() as $attr) 		{
			if ($attr->getIsRefAttr())
			{
				continue;
			}
			$dtl = new EnVerDtl();
			$dtl->setEnVerPK($ver->getMyPK());
			$dtl->setEnVer($ver->getEVer());
			$dtl->setEnName($ver->getNo());
			$dtl->setAttrKey($attr->getKey());
			$dtl->setAttrName($attr->getDesc());
			$dtl->setRDT($rdt);
			$dtl->setRec($WebUser->getName());
			/* match: String */
			$dtl->setNewVal($this->GetValStrByKey_String($attr->getKey()));
			$dtl->setMyPK((((($ver->getMyPK() . "_") . $attr->getKey()) . "_") . $dtl->getEnVer()));
			$dtl->Insert();
		}
	}
	protected function afterInsertUpdateAction () 
	{
		if (($this->getEnMap()->getHisFKEnumAttrs()->size() > 0))
			$this->RetrieveFromDBSources();
		if ($this->getEnMap()->IsAddRefName)
		{
			$this->ReSetNameAttrVal();
			$this->DirectUpdate();
		}
		return ;
	}
	protected function ReSetNameAttrVal () 
	{
		$attrs = $this->getEnMap()->getAttrs();
		foreach ($attrs as $attr) 		{
			if (($attr->getIsFKorEnum() ==  FALSE ))
				continue;
			$s = $this->GetValRefTextByKey($attr->getKey());
			$this->SetValByKey_String_String(($attr->getKey() . "Name"), $s);
		}
	}
	public function Copy_Entity ($fromEn) // [Entity fromEn]
	{
		foreach ($this->getEnMap()->getAttrs() as $attr) 		{
			$obj = $fromEn->GetValByKey($attr->getKey());
			if (($obj == NULL))
			{
				continue;
			}
			$this->SetValByKey_String_Object($attr->getKey(), $obj);
		}
	}
	public function Copy_Row ($fromRow) // [Row fromRow]
	{
		$attrs = $this->getEnMap()->getAttrs();
		foreach ($attrs as $attr) 		{
			try 
			{
				$this->SetValByKey_String_Object($attr->getKey(), $fromRow->GetValByKey($attr->getKey()));
			}
			catch (\Exception $e)
			{ /* empty */ }
		}
	}
	public function Copy_XmlEnXMLSysBP ($xmlen) // [BP.Sys.XML.XmlEn xmlen]
	{
		$attrs = $this->getEnMap()->getAttrs();
		foreach ($attrs as $attr) 		{
			$obj = NULL;
			try 
			{
				$obj = $xmlen->GetValByKey($attr->getKey());
			}
			catch (\Exception $e)
			{
				continue;
			}
			if ((($obj == NULL) || $obj->equals("")))
			{
				continue;
			}
			$this->SetValByKey_String_F($attr->getKey(), $xmlen->GetValByKey($attr->getKey()));
		}
	}
	public function Copy_Hashtable ($ht) // [Hashtable ht]
	{
		$keys = $ht->keySet();
		foreach ($keys as $k) 		{
			$obj = NULL;
			try 
			{
				$obj = $ht->get($k);
			}
			catch (\Exception $e)
			{
				continue;
			}
			if ((($obj == NULL) || $obj->equals("")))
			{
				continue;
			}
			$this->SetValByKey_String_Object($k, $obj);
		}
	}
	public function Copy_DataRow ($dr) // [DataRow dr]
	{
		foreach ($this->getEnMap()->getAttrs() as $attr) 		{
			try 
			{
				$this->SetValByKey_String_F($attr->getKey(), $dr->getValue($attr->getKey()));
			}
			catch (\Exception $e)
			{ /* empty */ }
		}
	}
	public function Copy_String ($refDoc) // [String refDoc]
	{
		foreach ($this->get_enMap()->getAttrs() as $attr) 		{
			/* match: String */
			$refDoc = $refDoc->replace(("@" . $attr->getKey()), $this->GetValStrByKey_String($attr->getKey()));
		}
		return $refDoc;
	}
	public function Copy () 
	{
		foreach ($this->getEnMap()->getAttrs() as $attr) 		{
			if (!$attr->getIsPK())
			{
				continue;
			}
			if (($attr->getMyDataType() == $DataType->AppInt))
			{
				$this->SetValByKey_String_I($attr->getKey(), 0);
			}
			else
			{
				$this->SetValByKey_String_String($attr->getKey(), "");
			}
		}
		try 
		{
			$this->SetValByKey_String_String("No", "");
		}
		catch (\Exception $e)
		{ /* empty */ }
	}
	public function verifyData () 
	{
		return  TRUE ;
	}
	protected function beforeUpdateInsertAction () 
	{
		switch ($this->getEnMap()->getEnType()) {
			case $View:
			case $XML:
			case $Ext:
				return  FALSE ;
			default:
				break;
		}
		$this->verifyData();
		return  TRUE ;
	}
	public function Update () 
	{
			/* match: aString */
		return $this->Update_aString(NULL);
	}
	public function Update_String_Object ($key1, $val1) // [String key1, Object val1]
	{
		$this->SetValByKey_String_Object($key1, $val1);
		$sql = "";
		if ((((($val1 instanceof Integer) || ($val1 instanceof Float)) || ($val1 instanceof Long)) || ($val1 instanceof BigDecimal)))
			$sql = (((((((((("UPDATE " . $this->getEnMap()->getPhysicsTable()) . " SET ") . $key1) . " =") . $val1) . " WHERE ") . $this->getPK()) . "='") . $this->getPKVal()) . "'");
		if ($val1 instanceof String)
			$sql = (((((((((("UPDATE " . $this->getEnMap()->getPhysicsTable()) . " SET ") . $key1) . " ='") . $val1) . "' WHERE ") . $this->getPK()) . "='") . $this->getPKVal()) . "'");
		return $this->RunSQL_String($sql);
	}
	public function Update_String_Object_String_Object ($key1, $val1, $key2, $val2) // [String key1, Object val1, String key2, Object val2]
	{
		$this->SetValByKey_String_Object($key1, $val1);
		$this->SetValByKey_String_Object($key2, $val2);
		$key1 = (($key1 . ",") . $key2);
			/* match: aString */
		return $this->Update_aString($key1->split("[,]", -1));
	}
	public function Update_String_Object_String_Object_String_Object ($key1, $val1, $key2, $val2, $key3, $val3) // [String key1, Object val1, String key2, Object val2, String key3, Object val3]
	{
		$this->SetValByKey_String_Object($key1, $val1);
		$this->SetValByKey_String_Object($key2, $val2);
		$this->SetValByKey_String_Object($key3, $val3);
		$key1 = (((($key1 . ",") . $key2) . ",") . $key3);
			/* match: aString */
		return $this->Update_aString($key1->split("[,]", -1));
	}
	public function Update_String_Object_String_Object_String_Object_String_Object ($key1, $val1, $key2, $val2, $key3, $val3, $key4, $val4) // [String key1, Object val1, String key2, Object val2, String key3, Object val3, String key4, Object val4]
	{
		$this->SetValByKey_String_Object($key1, $val1);
		$this->SetValByKey_String_Object($key2, $val2);
		$this->SetValByKey_String_Object($key3, $val3);
		$this->SetValByKey_String_Object($key4, $val4);
		$key1 = (((((($key1 . ",") . $key2) . ",") . $key3) . ",") . $key4);
			/* match: aString */
		return $this->Update_aString($key1->split("[,]", -1));
	}
	public function Update_String_Object_String_Object_String_Object_String_Object_String_Object ($key1, $val1, $key2, $val2, $key3, $val3, $key4, $val4, $key5, $val5) // [String key1, Object val1, String key2, Object val2, String key3, Object val3, String key4, Object val4, String key5, Object val5]
	{
		$this->SetValByKey_String_Object($key1, $val1);
		$this->SetValByKey_String_Object($key2, $val2);
		$this->SetValByKey_String_Object($key3, $val3);
		$this->SetValByKey_String_Object($key4, $val4);
		$this->SetValByKey_String_Object($key5, $val5);
		$key1 = (((((((($key1 . ",") . $key2) . ",") . $key3) . ",") . $key4) . ",") . $key5);
			/* match: aString */
		return $this->Update_aString($key1->split("[,]", -1));
	}
	public function Update_String_Object_String_Object_String_Object_String_Object_String_Object_String_Object ($key1, $val1, $key2, $val2, $key3, $val3, $key4, $val4, $key5, $val5, $key6, $val6) // [String key1, Object val1, String key2, Object val2, String key3, Object val3, String key4, Object val4, String key5, Object val5, String key6, Object val6]
	{
		$this->SetValByKey_String_Object($key1, $val1);
		$this->SetValByKey_String_Object($key2, $val2);
		$this->SetValByKey_String_Object($key3, $val3);
		$this->SetValByKey_String_Object($key4, $val4);
		$this->SetValByKey_String_Object($key5, $val5);
		$this->SetValByKey_String_Object($key6, $val6);
		$key1 = (((((((((($key1 . ",") . $key2) . ",") . $key3) . ",") . $key4) . ",") . $key5) . ",") . $key6);
			/* match: aString */
		return $this->Update_aString($key1->split("[,]", -1));
	}
	protected function beforeUpdate () 
	{
		return  TRUE ;
	}
	public function Update_aString ($keys) // [String[] keys]
	{
		$str = "";
		try 
		{
			$str = "@更新之前出现错误 ";
			if (!$this->beforeUpdate())
			{
				return 0;
			}
			$str = "@更新插入之前出现错误";
			if (!$this->beforeUpdateInsertAction())
			{
				return 0;
			}
			$str = "@更新时出现错�?";
			$i = EntityDBAccess::Update($this, $keys);
			$str = "@更新之后出现错误";
			if (($this->getEnMap()->getDepositaryOfEntity() == $Depositary->Application))
			{
				$Cash2019->UpdateRow($this, $String->valueOf($this->getPKVal()), $this->getRow());
			}
			$this->afterUpdate();
			$str = "@更新插入之后出现错误";
			$this->afterInsertUpdateAction();
			return $i;
		}
		catch (\RuntimeException $ex)
		{
			if (($ex->getMessage()->contains("将截断字符串") && $ex->getMessage()->contains("缺少")))
			{
				try 
				{
					$this->CheckPhysicsTable();
				}
				catch (Exception $e)
				{
					$e->printStackTrace();
				}
				$errs = "";
				foreach ($this->getEnMap()->getAttrs() as $attr) 				{
					if (($attr->getMyDataType() !=DataType->AppString))
					{
						continue;
					}
			/* match: String */
					if (($attr->getMaxLength() < $this->GetValStrByKey_String($attr->getKey())->length()))
					{
			/* match: String */
						$errs += (((((("@映射里面�?" . $attr->getKey()) . ",") . $attr->getDesc()) . ", 相对于输入的数据:{") . $this->GetValStrByKey_String($attr->getKey())) . "}, 太长�?");
					}
				}
				if (!$errs->equals(""))
				{
					throw new \RuntimeException(((((("@执行更新[" . $this) . "]出现错误@错误字段:") . $errs) . " <br>清你在提交一次�??") . $ex->getMessage()));
				}
				else
				{
					throw $ex;
				}
			}
			$Log->DefaultLogWriteLine($LogType->Error, $ex->getMessage());
			if ($SystemConfig->getIsDebug())
			{
				throw new \RuntimeException((((("@[" . $this->getEnDesc()) . "]更新期间出现错误:") . $str) . $ex->getMessage()));
			}
			else
			{
				throw $ex;
			}
		}
	}
	protected function afterUpdate () 
	{
		return ;
	}
	public function SaveBigTxtToDB ($saveToField, $bigTxt) // [String saveToField, String bigTxt]
	{
		$temp = ((((SystemConfig::getPathOfTemp() . "/") . $this->getEnMap()->getPhysicsTable()) . $this->getPKVal()) . ".tmp");
		$DataType->WriteFile($temp, $bigTxt);
		$this->SaveFileToDB($saveToField, $temp);
	}
	public function SaveFileToDB ($saveToField, $filefullName) // [String saveToField, String filefullName]
	{
		try 
		{
			DBAccess->SaveFileToDB($filefullName, $this->getEnMap()->getPhysicsTable(), $this->getPK(), $this->getPKVal(), $saveToField);
		}
		catch (\RuntimeException $ex)
		{
			$sql = "";
			if (DBAccess->getAppCenterDBType()->equals($DBType->MSSQL))
			{
				$sql = (((("ALTER TABLE " . $this->getEnMap()->getPhysicsTable()) . " ADD ") . $saveToField) . " Image NULL ");
			}
			if (DBAccess->getAppCenterDBType()->equals($DBType->Oracle))
			{
				$sql = (((("ALTER TABLE " . $this->getEnMap()->getPhysicsTable()) . " ADD ") . $saveToField) . " Blob NULL ");
			}
			if (DBAccess->getAppCenterDBType()->equals($DBType->MySQL))
			{
				$sql = (((("ALTER TABLE " . $this->getEnMap()->getPhysicsTable()) . " ADD ") . $saveToField) . " MediumBlob NULL ");
			}
			DBAccess::RunSQL($sql);
			throw new \RuntimeException(("@保存文件期间出现错误，有可能该字段没有被自动创建，现在已经执行创建修复数据表，请重新执行�?�?." . $ex->getMessage()));
		}
	}
	public function GetFileFromDB ($saveToField, $filefullName) // [String saveToField, String filefullName]
	{
		DBAccess->GetFileFromDB($filefullName, $this->getEnMap()->getPhysicsTable(), $this->getPK(), $this->getPKVal(), $saveToField);
		return NULL;
	}
	public function GetBigTextFromDB_String ($imgFieldName) // [String imgFieldName]
	{
		$tempFile = ((((SystemConfig::getPathOfTemp() . "/") . $this->getEnMap()->getPhysicsTable()) . $this->getPKVals()) . ".tmp");
		$file = new File($tempFile);
		if ($file->exists())
		{
			$file->delete();
			try 
			{
				$file->createNewFile();
			}
			catch (IOException $e)
			{
				$e->printStackTrace();
			}
		}
		else
		{
			try 
			{
				$file->createNewFile();
			}
			catch (IOException $e)
			{
				$e->printStackTrace();
			}
		}
		returnDBAccess->GetTextFileFromDB($tempFile, $this->getEnMap()->getPhysicsTable(), $this->getPK(), $this->getPKVal(), $imgFieldName);
	}
	public function GetBigTextFromDB_String_String ($imgFieldName, $codeType) // [String imgFieldName, String codeType]
	{
		$tempFile = ((((SystemConfig::getPathOfTemp() . "/") . $this->getEnMap()->getPhysicsTable()) . $this->getPKVals()) . ".tmp");
		$file = new File($tempFile);
		if ($file->exists())
		{
			$file->delete();
			try 
			{
				$file->createNewFile();
			}
			catch (IOException $e)
			{
				$e->printStackTrace();
			}
		}
		else
		{
			try 
			{
				$file->createNewFile();
			}
			catch (IOException $e)
			{
				$e->printStackTrace();
			}
		}
		returnDBAccess->GetTextFileFromDB($tempFile, $this->getEnMap()->getPhysicsTable(), $this->getPK(), $this->getPKVal(), $imgFieldName, $codeType);
	}
	public function Save () 
	{
		if ($this->getPK()->equals("OID"))
		{
			/* match: String */
			if (($this->GetValIntByKey_String("OID") == 0))
			{
				$this->Insert();
				return 1;
			}
			$this->Update();
			return 1;
		}
		if (((($this->getPK()->equals("MyPK") || $this->getPK()->equals("No")) || $this->getPK()->equals("WorkID")) || $this->getPK()->equals("NodeID")))
		{
			/* match: String */
			$pk = $this->GetValStrByKey_String($this->getPK());
			if (($pk->equals("") . ($pk . NULL)))
			{
				$this->Insert();
				return 1;
			}
			$i = $this->Update();
			if (($i == 0))
			{
				$this->Insert();
				return 1;
			}
			return $i;
		}
		if (($this->Update() == 0))
		{
			$this->Insert();
		}
		return 1;
	}
	protected function CreatePhysicsTable () 
	{
		switch (DBAccess->getAppCenterDBType()) {
			case $Oracle:
				DBAccess::RunSQL(SqlBuilder::GenerCreateTableSQLOfOra_OK($this));
				break;
			case $MSSQL:
				DBAccess::RunSQL(SqlBuilder::GenerCreateTableSQLOfMS($this));
				break;
			case $MySQL:
				DBAccess::RunSQL(SqlBuilder::GenerCreateTableSQLOfMySQL($this));
				break;
			default:
				throw new \RuntimeException("@未判断的数据库类型�??");
		}
		$this->CreateIndexAndPK();
	}
	protected function CreateIndexAndPK () 
	{
		$pkconut = $this->getPKCount();
		if (($pkconut == 1))
		{
			DBAccess->CreatePK($this->getEnMap()->getPhysicsTable(), $this->getPK(), $this->getEnMap()->getEnDBUrl()->getDBType());
			DBAccess->CreatIndex($this->getEnMap()->getPhysicsTable(), $this->getPK());
		}
		else
			if (($pkconut == 2))
			{
				$pk0 = $this->getPKs()[0];
				$pk1 = $this->getPKs()[1];
				DBAccess->CreatePK($this->getEnMap()->getPhysicsTable(), $pk0, $pk1, $this->getEnMap()->getEnDBUrl()->getDBType());
				DBAccess->CreatIndex($this->getEnMap()->getPhysicsTable(), $pk0, $pk1);
			}
			else
				if (($pkconut == 3))
				{
					$pk0 = $this->getPKs()[0];
					$pk1 = $this->getPKs()[1];
					$pk2 = $this->getPKs()[2];
					DBAccess->CreatePK($this->getEnMap()->getPhysicsTable(), $pk0, $pk1, $pk2, $this->getEnMap()->getEnDBUrl()->getDBType());
					DBAccess->CreatIndex($this->getEnMap()->getPhysicsTable(), $pk0, $pk1, $pk2);
				}
	}
	protected function CheckPhysicsTable_SQL () 
	{
		$table = $this->get_enMap()->getPhysicsTable();
		$dbtype = $this->get_enMap()->getEnDBUrl()->getDBType();
		$sqlFields = "";
		$sqlYueShu = "";
		$sqlFields = (("SELECT column_name as FName,data_type as FType,CHARACTER_MAXIMUM_LENGTH as FLen from information_schema.columns where table_name='" . $this->getEnMap()->getPhysicsTable()) . "'");
		$sqlYueShu = (("SELECT b.name, a.name FName from sysobjects b join syscolumns a on b.id = a.cdefault where a.id = object_id('" . $this->getEnMap()->getPhysicsTable()) . "') ");
		$dtAttr = DBAccess->RunSQLReturnTable($sqlFields);
		$dtYueShu = DBAccess->RunSQLReturnTable($sqlYueShu);
		$attrs = $this->get_enMap()->getAttrs();
		foreach ($attrs as $attr) 		{
			if ($attr->getIsRefAttr())
			{
				continue;
			}
			$FType = "";
			$Flen = "";
			$isHave =  FALSE ;
			foreach ($dtAttr->Rows as $dr) 			{
				if ($dr->getValue("FName")->toLowerCase()->equals($attr->getField()->toLowerCase()))
				{
					$isHave =  TRUE ;
					$FType = (( (($dr->getValue("FType") instanceof String)) ? $dr->getValue("FType") : NULL ));
					$Flen = ( (($dr->getValue("FLen") == NULL)) ? "0" : $dr->getValue("FLen") );
					break;
				}
			}
			if (($isHave ==  FALSE ))
			{
				switch ($attr->getMyDataType()) {
					case $DataType->AppString:
					case $DataType->AppDate:
					case $DataType->AppDateTime:
						$len = $attr->getMaxLength();
						if (($len == 0))
						{
							$len = 200;
						}
						if ((($dbtype == $DBType->Access) && ($len >= 254)))
						{
							DBAccess::RunSQL((((((("ALTER TABLE " . $this->getEnMap()->getPhysicsTable()) . " ADD ") . $attr->getField()) . "  Memo DEFAULT '") . $attr->getDefaultVal()) . "' NULL"));
						}
						else
						{
							DBAccess::RunSQL((((((((("ALTER TABLE " . $this->getEnMap()->getPhysicsTable()) . " ADD ") . $attr->getField()) . " NVARCHAR(") . $len) . ") DEFAULT '") . $attr->getDefaultVal()) . "' NULL"));
						}
						continue;
					case $DataType->AppInt:
						if ($attr->getIsPK())
						{
							DBAccess::RunSQL((((((("ALTER TABLE " . $this->getEnMap()->getPhysicsTable()) . " ADD ") . $attr->getField()) . " INT DEFAULT '") . $attr->getDefaultVal()) . "' NOT NULL"));
						}
						else
						{
							DBAccess::RunSQL((((((("ALTER TABLE " . $this->getEnMap()->getPhysicsTable()) . " ADD ") . $attr->getField()) . " INT DEFAULT '") . $attr->getDefaultVal()) . "'   NULL"));
						}
						continue;
					case $DataType->AppBoolean:
						DBAccess::RunSQL((((((("ALTER TABLE " . $this->getEnMap()->getPhysicsTable()) . " ADD ") . $attr->getField()) . " INT DEFAULT '") . $attr->getDefaultVal()) . "'   NULL"));
						continue;
					case $DataType->AppFloat:
					case $DataType->AppMoney:
					case $DataType->AppRate:
					case $DataType->AppDouble:
						DBAccess::RunSQL((((((("ALTER TABLE " . $this->getEnMap()->getPhysicsTable()) . " ADD ") . $attr->getField()) . " FLOAT DEFAULT '") . $attr->getDefaultVal()) . "' NULL"));
						continue;
					default:
						throw new \RuntimeException(((("error MyFieldType= " . $attr->getMyFieldType()) . " key=") . $attr->getKey()));
				}
			}
			if (($isHave ==  FALSE ))
				continue;
			switch ($attr->getMyDataType()) {
				case $DataType->AppString:
				case $DataType->AppDate:
				case $DataType->AppDateTime:
					if ($FType->toLowerCase()->contains("char"))
					{
						if ($attr->getIsPK())
							continue;
						if (($Flen . NULL))
						{
							throw new \RuntimeException(((("" . $attr->getKey()) . " -") . $sqlFields));
						}
						$len = $Integer->parseInt($Flen);
						if (($len < $attr->getMaxLength()))
						{
							try 
							{
								if (($attr->getMaxLength() >= 4000))
								{
									DBAccess::RunSQL((((("alter table " . $this->getEnMap()->getPhysicsTable()) . " ALTER column  ") . $attr->getKey()) . " NVARCHAR(4000)"));
								}
								else
								{
									DBAccess::RunSQL((((((("alter table " . $this->getEnMap()->getPhysicsTable()) . " ALTER column  ") . $attr->getKey()) . " NVARCHAR(") . $attr->getMaxLength()) . ")"));
								}
							}
							catch (\Exception $e)
							{
								foreach ($dtYueShu->Rows as $dr) 								{
									if ($dr->getValue("FName")->toLowerCase()->equals($attr->getKey()->toLowerCase()))
									{
										DBAccess::RunSQL(((("alter table " . $table) . " drop constraint ") . $dr->getValue(0)));
									}
								}
								if (($attr->getMaxLength() >= 4000))
								{
									DBAccess::RunSQL((((("alter table " . $this->getEnMap()->getPhysicsTable()) . " ALTER column ") . $attr->getKey()) . " NVARCHAR(4000)"));
								}
								else
								{
									DBAccess::RunSQL((((((("alter table " . $this->getEnMap()->getPhysicsTable()) . " ALTER column  ") . $attr->getKey()) . " NVARCHAR(") . $attr->getMaxLength()) . ")"));
								}
							}
						}
					}
					else
					{
						foreach ($dtYueShu->Rows as $dr) 						{
							if ($dr->getValue("FName")->toLowerCase()->equals($attr->getKey()->toLowerCase()))
							{
								DBAccess::RunSQL(((("alter table " . $table) . " drop constraint ") . $dr->getValue(0)));
							}
						}
						DBAccess::RunSQL(((("ALTER TABLE " . $this->getEnMap()->getPhysicsTable()) . " drop column ") . $attr->getField()));
						DBAccess::RunSQL((((((((("ALTER TABLE " . $this->getEnMap()->getPhysicsTable()) . " ADD ") . $attr->getField()) . " NVARCHAR(") . $attr->getMaxLength()) . ") DEFAULT '") . $attr->getDefaultVal()) . "' NULL"));
						continue;
					}
					break;
				case $DataType->AppInt:
				case $DataType->AppBoolean:
					if (!$FType->equals("int"))
					{
						foreach ($dtYueShu->Rows as $dr) 						{
							if ($dr->getValue("FName")->toLowerCase()->equals($attr->getKey()->toLowerCase()))
							{
								DBAccess::RunSQL(((("alter table " . $table) . " drop constraint ") . $dr->getValue(0)));
							}
						}
						DBAccess::RunSQL(((("ALTER TABLE " . $this->getEnMap()->getPhysicsTable()) . " drop column ") . $attr->getField()));
						DBAccess::RunSQL((((((("ALTER TABLE " . $this->getEnMap()->getPhysicsTable()) . " ADD ") . $attr->getField()) . " INT DEFAULT '") . $attr->getDefaultVal()) . "' NULL"));
						continue;
					}
					break;
				case $DataType->AppFloat:
				case $DataType->AppMoney:
				case $DataType->AppRate:
				case $DataType->AppDouble:
					if (!$FType->equals("float"))
					{
						foreach ($dtYueShu->Rows as $dr) 						{
							if ($dr->getValue("FName")->toLowerCase()->equals($attr->getKey()->toLowerCase()))
							{
								DBAccess::RunSQL(((("alter table " . $table) . " drop constraint ") . $dr->getValue(0)));
							}
						}
						DBAccess::RunSQL(((("ALTER TABLE " . $this->getEnMap()->getPhysicsTable()) . " drop column ") . $attr->getField()));
						DBAccess::RunSQL((((((("ALTER TABLE " . $this->getEnMap()->getPhysicsTable()) . " ADD ") . $attr->getField()) . " FLOAT DEFAULT '") . $attr->getDefaultVal()) . "' NULL"));
						continue;
					}
					break;
				default:
					throw new \RuntimeException(((("error MyFieldType= " . $attr->getMyFieldType()) . " key=") . $attr->getKey()));
			}
		}
	}
	public function CheckPhysicsTable () 
	{
		$this->set_enMap($this->getEnMap());
		$map = $this->getEnMap();
		if ((((($map->getEnType() == EnType::$View) || ($map->getEnType() == EnType::$XML)) || ($map->getEnType() == EnType::$ThirdPartApp)) || ($map->getEnType() == EnType::$Ext)))
		{
			return ;
		}
		if ((DBAccess->IsExitsObject($this->get_enMap()->getPhysicsTable()) ==  FALSE ))
		{
			$this->CreatePhysicsTable();
			return ;
		}
		switch ($SystemConfig->getAppCenterDBType()) {
			case $MSSQL:
				$this->CheckPhysicsTable_SQL();
				break;
			case $Oracle:
				$this->CheckPhysicsTable_Ora();
				break;
			case $MySQL:
				$this->CheckPhysicsTable_MySQL();
				break;
			case $Informix:
				$this->CheckPhysicsTable_Informix();
				break;
			default:
				break;
		}
		$this->CreateIndexAndPK();
	}
	protected function CheckPhysicsTable_Informix () 
	{
		$sql = (("SELECT *  FROM " . $this->getEnMap()->getPhysicsTable()) . " WHERE 1=2");
		$dt =DBAccess->RunSQLReturnTable($sql);
		foreach ($this->getEnMap()->getAttrs() as $attr) 		{
			if (($attr->getMyFieldType() == FieldType::$RefText))
			{
				continue;
			}
			if ($attr->getIsPK())
			{
				continue;
			}
			if ($dt->Columns->contains($attr->getKey()))
			{
				continue;
			}
			if ($attr->getKey()->equals("AID"))
			{
				DBAccess::RunSQL((((("ALTER TABLE " . $this->getEnMap()->getPhysicsTable()) . " ADD ") . $attr->getField()) . " INT  Identity(1,1)"));
				continue;
			}
			switch ($attr->getMyDataType()) {
				case $DataType->AppString:
				case $DataType->AppDate:
				case $DataType->AppDateTime:
					$len = $attr->getMaxLength();
					if (($len == 0))
					{
						$len = 200;
					}
					if (($len >= 254))
					{
						DBAccess::RunSQL((((((((("alter table " . $this->getEnMap()->getPhysicsTable()) . " add ") . $attr->getField()) . " lvarchar(") . $len) . ") default '") . $attr->getDefaultVal()) . "'"));
					}
					else
					{
						DBAccess::RunSQL((((((((("alter table " . $this->getEnMap()->getPhysicsTable()) . " add ") . $attr->getField()) . " varchar(") . $len) . ") default '") . $attr->getDefaultVal()) . "'"));
					}
					break;
				case $DataType->AppInt:
				case $DataType->AppBoolean:
					DBAccess::RunSQL((((((("ALTER TABLE " . $this->getEnMap()->getPhysicsTable()) . " ADD ") . $attr->getField()) . " INT8 DEFAULT ") . $attr->getDefaultVal()) . " "));
					break;
				case $DataType->AppFloat:
				case $DataType->AppMoney:
				case $DataType->AppRate:
				case $DataType->AppDouble:
					DBAccess::RunSQL((((((("ALTER TABLE " . $this->getEnMap()->getPhysicsTable()) . " ADD ") . $attr->getField()) . " FLOAT DEFAULT  ") . $attr->getDefaultVal()) . " "));
					break;
				default:
					throw new \RuntimeException(((("error MyFieldType= " . $attr->getMyFieldType()) . " key=") . $attr->getKey()));
			}
		}
		foreach ($this->getEnMap()->getAttrs() as $attr) 		{
			if (($attr->getMyFieldType() == FieldType::$RefText))
			{
				continue;
			}
			if ((((((($attr->getMyDataType() == $DataType->AppDouble) || ($attr->getMyDataType() == $DataType->AppFloat)) || ($attr->getMyDataType() == $DataType->AppInt)) || ($attr->getMyDataType() == $DataType->AppMoney)) || ($attr->getMyDataType() == $DataType->AppBoolean)) || ($attr->getMyDataType() == $DataType->AppRate)))
			{
				continue;
			}
			$dt = new DataTable();
			$sql = ((((("select c.*  from syscolumns c inner join systables t on c.tabid = t.tabid where t.tabname = lower('" . $this->getEnMap()->getPhysicsTable()->toLowerCase()) . "') and c.colname = lower('") . $attr->getKey()) . "') and c.collength < ") . $attr->getMaxLength());
			$dt = $this->RunSQLReturnTable($sql);
			if (($dt->Rows->size() == 0))
			{
				continue;
			}
			foreach ($dt->Rows as $dr) 			{
				try 
				{
					if (($attr->getMaxLength() >= 255))
					{
						$this->RunSQL_String((((((((("alter table " . $dr->getValue("owner")) . ".") . $this->getEnMap()->getPhysicsTableExt()) . " modify ") . $attr->getField()) . " lvarchar(") . $attr->getMaxLength()) . ")"));
					}
					else
					{
						$this->RunSQL_String((((((((("alter table " . $dr->getValue("owner")) . ".") . $this->getEnMap()->getPhysicsTableExt()) . " modify ") . $attr->getField()) . " varchar(") . $attr->getMaxLength()) . ")"));
					}
				}
				catch (\RuntimeException $ex)
				{
					Log->DebugWriteWarning($ex->getMessage());
				}
			}
		}
		$attrs = $this->get_enMap()->getHisEnumAttrs();
		foreach ($attrs as $attr) 		{
			if (($attr->getMyDataType() != $DataType->AppInt))
			{
				continue;
			}
			$sql = (((((("SELECT DATA_TYPE FROM ALL_TAB_COLUMNS WHERE OWNER = '" . $SystemConfig->getUser()->toUpperCase()) . "' AND TABLE_NAME='") . $this->getEnMap()->getPhysicsTableExt()->toLowerCase()) . "' AND COLUMN_NAME='") . $attr->getField()->toLowerCase()) . "'");
			$val = DBAccess->RunSQLReturnString($sql);
			if (($val . NULL))
			{
				$Log->DefaultLogWriteLineError(("@没有�?测到字段:" . $attr->getKey()));
			}
			if (($val->indexOf("CHAR") != -1))
			{
				try 
				{
					$this->RunSQL_String((((("alter table  " . $this->getEnMap()->getPhysicsTableExt()) . " modify ") . $attr->getField()) . " NUMBER "));
				}
				catch (\RuntimeException $ex)
				{
					$Log->DefaultLogWriteLineError(((((("运行sql 失败:alter table  " . $this->getEnMap()->getPhysicsTableExt()) . " modify ") . $attr->getField()) . " NUMBER ") . $ex->getMessage()));
				}
			}
		}
		$attrs = $this->get_enMap()->getHisEnumAttrs();
		foreach ($attrs as $attr) 		{
			if (($attr->getMyDataType() != $DataType->AppInt))
			{
				continue;
			}
			if (($attr->UITag == NULL))
			{
				continue;
			}
			$strs = $attr->UITag->split("[@]", -1);
			$ens = new SysEnums();
			$ens->Delete($SysEnumAttr->EnumKey, $attr->getUIBindKey());
			foreach ($strs as $s) 			{
				if (($DataType->IsNullOrEmpty($s) ==  TRUE ))
				{
					continue;
				}
				$vk = $s->split("[=]", -1);
				$se = new SysEnum();
				$se->setIntKey($Integer->parseInt($vk[0]));
				$se->setLab($vk[1]);
				$se->setEnumKey($attr->getUIBindKey());
				$se->Insert();
			}
		}
		$this->CreateIndexAndPK();
	}
	protected function CheckPhysicsTable_MySQL () 
	{
		$sql = (("SELECT *  FROM " . $this->get_enMap()->getPhysicsTable()) . " WHERE 1=2");
		$dt =DBAccess->RunSQLReturnTable($sql);
		$map = $this->get_enMap();
		$sql = (((("SELECT character_maximum_length as Len, table_schema as OWNER, column_Name FROM information_schema.columns WHERE TABLE_SCHEMA='" . SystemConfig::getAppCenterDBDatabase()) . "' AND table_name ='") . $map->getPhysicsTable()) . "'");
		$dtScheam = $this->RunSQLReturnTable($sql);
		foreach ($map->getAttrs() as $attr) 		{
			if (($attr->getMyFieldType() == FieldType::$RefText))
				continue;
			if ($attr->getIsPK())
				continue;
			if (($dt->Columns->get($attr->getKey()->toLowerCase()) != NULL))
			{
				if ((((((($attr->getMyDataType() == $DataType->AppDouble) || ($attr->getMyDataType() == $DataType->AppFloat)) || ($attr->getMyDataType() == $DataType->AppInt)) || ($attr->getMyDataType() == $DataType->AppMoney)) || ($attr->getMyDataType() == $DataType->AppBoolean)) || ($attr->getMyDataType() == $DataType->AppRate)))
				{
					continue;
				}
				$maxLen = $attr->getMaxLength();
				foreach ($dtScheam->Rows as $dr) 				{
					$name = $dr->getValue("column_Name");
					if (($name->equals($attr->getKey()) ==  FALSE ))
						continue;
					if ((($dr->getValue("Len") == NULL) || ($dr->getValue("Len")->length() == 0)))
					{
						continue;
					}
					$len = $dr->getValue("Len");
					if (($DataType->IsNullOrEmpty($len) ==  TRUE ))
						continue;
					$lenInt = $Integer->parseInt($len);
					if (($lenInt >= $maxLen))
						continue;
					if (($attr->getMaxLength() >= 3000))
						$this->RunSQL_String((((((("alter table " . $dr->getValue("OWNER")) . ".") . $this->get_enMap()->getPhysicsTableExt()) . " modify ") . $attr->getField()) . " text"));
					else
						$this->RunSQL_String((((((((("alter table " . $dr->getValue("OWNER")) . ".") . $this->get_enMap()->getPhysicsTableExt()) . " modify ") . $attr->getField()) . " NVARCHAR(") . $attr->getMaxLength()) . ")"));
				}
				continue;
			}
			switch ($attr->getMyDataType()) {
				case $DataType->AppString:
					$len = $attr->getMaxLength();
					if (($len == 0))
						$len = 200;
					if (($len >= 3000))
					{
						DBAccess::RunSQL((((("ALTER TABLE " . $this->get_enMap()->getPhysicsTable()) . " ADD ") . $attr->getField()) . " TEXT "));
					}
					else
					{
						DBAccess::RunSQL((((((((("ALTER TABLE " . $this->get_enMap()->getPhysicsTable()) . " ADD ") . $attr->getField()) . " VARCHAR(") . $len) . ") DEFAULT '") . $attr->getDefaultVal()) . "' NULL"));
					}
					break;
				case $DataType->AppDate:
				case $DataType->AppDateTime:
					DBAccess::RunSQL((((("ALTER TABLE " . $this->get_enMap()->getPhysicsTable()) . " ADD ") . $attr->getField()) . " VARCHAR(20)  NULL"));
					break;
				case $DataType->AppInt:
				case $DataType->AppBoolean:
					DBAccess::RunSQL((((((("ALTER TABLE " . $this->get_enMap()->getPhysicsTable()) . " ADD ") . $attr->getField()) . " INT DEFAULT ") . $attr->getDefaultVal()) . " NULL"));
					break;
				case $DataType->AppFloat:
					DBAccess::RunSQL((((((((("ALTER TABLE " . $this->get_enMap()->getPhysicsTable()) . " ADD ") . $attr->getField()) . " FLOAT (11,2) DEFAULT '") . $attr->getDefaultVal()) . "' NULL COMMENT '") . $attr->getDesc()) . "'"));
					break;
				case $DataType->AppMoney:
					DBAccess::RunSQL((((((((("ALTER TABLE " . $this->get_enMap()->getPhysicsTable()) . " ADD ") . $attr->getField()) . " DECIMAL (20,4) DEFAULT '") . $attr->getDefaultVal()) . "' NULL COMMENT '") . $attr->getDesc()) . "'"));
					break;
				case $DataType->AppDouble:
					DBAccess::RunSQL((((((((("ALTER TABLE " . $this->get_enMap()->getPhysicsTable()) . " ADD ") . $attr->getField()) . " DOUBLE DEFAULT '") . $attr->getDefaultVal()) . "' NULL COMMENT '") . $attr->getDesc()) . "'"));
					break;
				default:
					throw new \RuntimeException(((("error MyFieldType= " . $attr->getMyFieldType()) . " key=") . $attr->getKey()));
			}
		}
	}
	protected function CheckPhysicsTable_Ora () 
	{
		$sql = (("SELECT *  FROM " . $this->getEnMap()->getPhysicsTable()) . " WHERE 1=2");
		$dt =DBAccess->RunSQLReturnTable($sql);
		foreach ($this->getEnMap()->getAttrs() as $attr) 		{
			if (($attr->getMyFieldType() == FieldType::$RefText))
			{
				continue;
			}
			if ($attr->getIsPK())
			{
				continue;
			}
			if ($dt->Columns->contains($attr->getKey()))
			{
				continue;
			}
			if ($attr->getKey()->equals("AID"))
			{
				DBAccess::RunSQL((((("ALTER TABLE " . $this->getEnMap()->getPhysicsTable()) . " ADD ") . $attr->getField()) . " INT  Identity(1,1)"));
				continue;
			}
			switch ($attr->getMyDataType()) {
				case $DataType->AppString:
				case $DataType->AppDate:
				case $DataType->AppDateTime:
					$len = $attr->getMaxLength();
					if (($len == 0))
					{
						$len = 200;
					}
					DBAccess::RunSQL((((((((("ALTER TABLE " . $this->getEnMap()->getPhysicsTable()) . " ADD ") . $attr->getField()) . " VARCHAR(") . $len) . ") DEFAULT '") . $attr->getDefaultVal()) . "' NULL"));
					break;
				case $DataType->AppInt:
				case $DataType->AppBoolean:
					DBAccess::RunSQL((((((("ALTER TABLE " . $this->getEnMap()->getPhysicsTable()) . " ADD ") . $attr->getField()) . " INT DEFAULT ") . $attr->getDefaultVal()) . "  NULL"));
					break;
				case $DataType->AppFloat:
				case $DataType->AppMoney:
				case $DataType->AppRate:
				case $DataType->AppDouble:
					DBAccess::RunSQL((((((("ALTER TABLE " . $this->getEnMap()->getPhysicsTable()) . " ADD ") . $attr->getField()) . " FLOAT DEFAULT '") . $attr->getDefaultVal()) . "' NULL"));
					break;
				default:
					throw new \RuntimeException(((("error MyFieldType= " . $attr->getMyFieldType()) . " key=") . $attr->getKey()));
			}
		}
		foreach ($this->getEnMap()->getAttrs() as $attr) 		{
			if (($attr->getMyFieldType() == FieldType::$RefText))
			{
				continue;
			}
			if ((((((($attr->getMyDataType() == $DataType->AppDouble) || ($attr->getMyDataType() == $DataType->AppFloat)) || ($attr->getMyDataType() == $DataType->AppInt)) || ($attr->getMyDataType() == $DataType->AppMoney)) || ($attr->getMyDataType() == $DataType->AppBoolean)) || ($attr->getMyDataType() == $DataType->AppRate)))
			{
				continue;
			}
			$dt = new DataTable();
			$sql = ((((((("SELECT DATA_LENGTH AS LEN, OWNER FROM ALL_TAB_COLUMNS WHERE OWNER = '" . $SystemConfig->getUser()->toUpperCase()) . "' AND upper(TABLE_NAME)='") . $this->getEnMap()->getPhysicsTableExt()->toUpperCase()) . "' AND UPPER(COLUMN_NAME)='") . $attr->getField()->toUpperCase()) . "' AND DATA_LENGTH < ") . $attr->getMaxLength());
			$dt = $this->RunSQLReturnTable($sql);
			if (($dt->Rows->size() == 0))
			{
				continue;
			}
			foreach ($dt->Rows as $dr) 			{
				try 
				{
					$this->RunSQL_String((((((((("alter table " . $dr->getValue("OWNER")) . ".") . $this->getEnMap()->getPhysicsTableExt()) . " modify ") . $attr->getField()) . " varchar2(") . $attr->getMaxLength()) . ")"));
				}
				catch (\RuntimeException $ex)
				{
					Log->DebugWriteWarning($ex->getMessage());
				}
			}
		}
		$attrs = $this->get_enMap()->getHisEnumAttrs();
		foreach ($attrs as $attr) 		{
			if (($attr->getMyDataType() != $DataType->AppInt))
			{
				continue;
			}
			$sql = (((((("SELECT DATA_TYPE FROM ALL_TAB_COLUMNS WHERE OWNER = '" . $SystemConfig->getUser()->toUpperCase()) . "' AND upper(TABLE_NAME)='") . $this->getEnMap()->getPhysicsTableExt()->toUpperCase()) . "' AND UPPER(COLUMN_NAME)='") . $attr->getField()->toUpperCase()) . "' ");
			$val = DBAccess->RunSQLReturnString($sql);
			if (($val . NULL))
			{
				$Log->DefaultLogWriteLineError(("@没有�?测到字段eunm" . $attr->getKey()));
			}
			if (($val->indexOf("CHAR") != -1))
			{
				try 
				{
					$this->RunSQL_String((((("alter table  " . $this->getEnMap()->getPhysicsTableExt()) . " modify ") . $attr->getField()) . " NUMBER "));
				}
				catch (\RuntimeException $ex)
				{
					$Log->DefaultLogWriteLineError(((((("运行sql 失败:alter table  " . $this->getEnMap()->getPhysicsTableExt()) . " modify ") . $attr->getField()) . " NUMBER ") . $ex->getMessage()));
				}
			}
		}
		$attrs = $this->get_enMap()->getHisEnumAttrs();
		foreach ($attrs as $attr) 		{
			if (($attr->getMyDataType() != $DataType->AppInt))
			{
				continue;
			}
			if (($attr->UITag == NULL))
			{
				continue;
			}
			$strs = $attr->UITag->split("[@]", -1);
			$ens = new SysEnums();
			$ens->Delete($SysEnumAttr->EnumKey, $attr->getUIBindKey());
			foreach ($strs as $s) 			{
				if (($DataType->IsNullOrEmpty($s) ==  TRUE ))
				{
					continue;
				}
				$vk = $s->split("[=]", -1);
				$se = new SysEnum();
				$se->setIntKey($Integer->parseInt($vk[0]));
				$se->setLab($vk[1]);
				$se->setEnumKey($attr->getUIBindKey());
				$se->Insert();
			}
		}
		$this->CreateIndexAndPK();
	}
	public function ToJson () 
	{
			/* match: Boolean */
		return $this->ToJson_Boolean( TRUE );
	}
	public function ToJson_Boolean ($isInParaFields) // [Boolean isInParaFields]
	{
		$ht = $this->getRow();
		if (($isInParaFields ==  FALSE ))
		{
			$ht->put("EnName", $this);
			return $BP->Tools->Json->ToJsonEntityModel($ht);
		}
		if (($ht->containsKey("AtPara") ==  TRUE ))
		{
			$ap = $this->getAtPara();
			foreach ($ap->getHisHT()->keySet() as $key) 			{
				$ht->put($key, $ap->getHisHT()->get($key));
			}
			$ht->remove("_ATObj_");
		}
		return $BP->Tools->Json->ToJson($ht,  FALSE );
	}
	public function getatPara () 
	{
		$tempVar = $this->getRow()->GetValByKey("_ATObj_");
		$at = (( (($tempVar instanceof AtPara)) ? $tempVar : NULL ));
		if (($at != NULL))
		{
			return $at;
		}
		try 
		{
			/* match: String */
			$atParaStr = $this->GetValStringByKey_String("AtPara");
			if ($DataType->IsNullOrEmpty($atParaStr))
			{
				$this->InitParaFields();
			/* match: String */
				$atParaStr = $this->GetValStringByKey_String("AtPara");
				if ($DataType->IsNullOrEmpty($atParaStr))
				{
					$atParaStr = "";
				}
				$at = new AtPara($atParaStr);
				$this->SetValByKey("_ATObj_", $at);
				return $at;
			}
			$at = new AtPara($atParaStr);
			$this->SetValByKey("_ATObj_", $at);
			return $at;
		}
		catch (\RuntimeException $ex)
		{
			throw new \RuntimeException(((("@获取参数AtPara时出现异�?" . $ex->getMessage()) . "，可能是您没有加入约定的参数字段AtPara. ") . $ex->getMessage()));
		}
	}
	public function DTSMapToSys_MapData ($fk_mapdata) // [String fk_mapdata]
	{
		if ($DataType->IsNullOrEmpty($fk_mapdata))
		{
			$fk_mapdata = $this->getClassIDOfShort();
		}
		$map = $this->getEnMap();
		$md = new MapData();
		try 
		{
			$md->setNo($fk_mapdata);
			if (($md->RetrieveFromDBSources() == 0))
				$md->Insert();
			$md->setEnPK($this->getPK());
			$md->setEnsName($this->getClassID());
			$md->setName($map->getEnDesc());
			$md->setPTable($map->getPhysicsTable());
			$md->Update();
			$this->DTSMapToSys_MapData_InitMapAttr($map->getAttrs(), $fk_mapdata);
			$dtls = $map->getDtls();
			foreach ($dtls->ToJavaList() as $dtl) 			{
				$mdtl = new MapDtl();
				$enDtl = $dtl->getEns()->getNewEntity();
				$mdtl->setNo($enDtl->getClassIDOfShort());
				if (($mdtl->RetrieveFromDBSources() == 0))
					$mdtl->Insert();
				$mdtl->setName($enDtl->getEnDesc());
				$mdtl->setFK_MapData($fk_mapdata);
				$mdtl->setPTable($enDtl->getEnMap()->getPhysicsTable());
				$mdtl->setRefPK($dtl->getRefKey());
				$mdtl->Update();
				$this->DTSMapToSys_MapData_InitMapAttr($enDtl->getEnMap()->getAttrs(), $enDtl->getClassIDOfShort());
			}
		}
		catch (Exception $e)
		{
			$e->printStackTrace();
		}
		return $md;
	}
	protected function DTSMapToSys_MapData_InitMapAttr ($attrs, $fk_mapdata) // [Attrs attrs, String fk_mapdata]
	{
		foreach ($attrs->ToJavaList() as $attr) 		{
			if ($attr->getIsRefAttr())
				continue;
			$mattr = new MapAttr();
			$mattr->setKeyOfEn($attr->getKey());
			$mattr->setFK_MapData($fk_mapdata);
			$mattr->setMyPK((($mattr->getFK_MapData() . "_") . $mattr->getKeyOfEn()));
			$mattr->RetrieveFromDBSources();
			$mattr->setName($attr->getDesc());
			$mattr->setDefVal($attr->getDefaultVal());
			$mattr->setKeyOfEn($attr->getField());
			$mattr->setMaxLen($attr->getMaxLength());
			$mattr->setMinLen($attr->getMinLength());
			$mattr->setUIBindKey($attr->getUIBindKey());
			$mattr->setUIIsLine($attr->UIIsLine);
			$mattr->setUIHeight(0);
			if (($attr->getMaxLength() > 3000))
				$mattr->setUIHeight(10);
			$mattr->setUIWidth($attr->getUIWidth());
			$mattr->setMyDataType($attr->getMyDataType());
			$mattr->setUIRefKey($attr->getUIRefKeyValue());
			$mattr->setUIRefKeyText($attr->getUIRefKeyText());
			$mattr->setUIVisible($attr->getUIVisible());
			switch ($attr->getMyFieldType()) {
				case $Enum:
				case $PKEnum:
					$mattr->setUIContralType($attr->getUIContralType());
					$mattr->setLGType(FieldTypeS::$Enum);
					$mattr->setUIIsEnable($attr->getUIIsReadonly());
					break;
				case $FK:
				case $PKFK:
					$mattr->setUIContralType($attr->getUIContralType());
					$mattr->setLGType(FieldTypeS::$FK);
					$mattr->setUIRefKey("No");
					$mattr->setUIRefKeyText("Name");
					$mattr->setUIIsEnable($attr->getUIIsReadonly());
					break;
				default:
					$mattr->setUIContralType(UIContralType::$TB);
					$mattr->setLGType(FieldTypeS::$Normal);
					$mattr->setUIIsEnable(!$attr->getUIIsReadonly());
					switch ($attr->getMyDataType()) {
						case $DataType->AppBoolean:
							$mattr->setUIContralType(UIContralType::$CheckBok);
							$mattr->setUIIsEnable($attr->getUIIsReadonly());
							break;
						case $DataType->AppDate:
							break;
						case $DataType->AppDateTime:
							break;
						default:
							break;
					}
					break;
			}
			$mattr->Save();
		}
	}
	public function getClassIDOfShort () 
	{
		$clsID = $this->getClassID();
		return $clsID->substring(($clsID->lastIndexOf('.') + 1));
	}
	public function getHisDBVarStr () 
	{
		return $SystemConfig->getAppCenterDBVarStr();
	}
	public function getHisUAC () 
	{
		if (($this->_HisUAC == NULL))
		{
			$this->_HisUAC = UAC::constructor__();
			if ($WebUser->getNo()->equals("admin"))
			{
				$this->_HisUAC->IsAdjunct =  FALSE ;
				$this->_HisUAC->IsDelete =  TRUE ;
				$this->_HisUAC->IsInsert =  TRUE ;
				$this->_HisUAC->IsUpdate =  TRUE ;
				$this->_HisUAC->IsView =  TRUE ;
			}
		}
		return $this->_HisUAC;
	}
	public function toString () 
	{
		return $this->getClass()->getName();
	}
	public function CreateInstance () 
	{
		$tempVar = NULL;
		try 
		{
			$tempVar = $this->getClass()->newInstance();
		}
		catch (Exception $e)
		{
			$e->printStackTrace();
		}
		return (( (($tempVar instanceof Entity)) ? $tempVar : NULL ));
	}
	protected function ResetDefaultValRowValues () 
	{
		if (($this->get_enMap() == NULL))
			return ;
		$attrs = $this->get_enMap()->getAttrs();
		foreach ($attrs as $attr) 		{
			$key = $attr->getKey();
			/* match: String_String */
			$v = $this->GetValStringByKey_String_String($key, NULL);
			if ((($v . NULL) . ($v->indexOf('@') == -1)))
				continue;
			if ($v->equals("@WebUser.getNo()"))
			{
				$this->SetValByKey_String_F($key, $WebUser->getNo());
				continue;
			}
			else
				if ($v->equals("@WebUser.getName()"))
				{
					$this->SetValByKey_String_F($key, $WebUser->getName());
					continue;
				}
				else
					if ($v->equals("@WebUser.getFK_Dept()"))
					{
						$this->SetValByKey_String_F($key, $WebUser->getFK_Dept());
						continue;
					}
					else
						if ($v->equals("@WebUser.getFK_DeptName"))
						{
							$this->SetValByKey_String_F($key, $WebUser->getFK_DeptName());
							continue;
						}
						else
							if ($v->equals("@WebUser.getFK_DeptNameOfFull"))
							{
								$this->SetValByKey_String_F($key, $WebUser->getFK_DeptNameOfFull());
								continue;
							}
							else
								if ($v->equals("@RDT"))
								{
									if (($attr->getMyDataType() == $DataType->AppDate))
									{
										$this->SetValByKey_String_F($attr->getKey(), $DataType->getCurrentDateByFormart("yyyy-MM-dd"));
									}
									if (($attr->getMyDataType() == $DataType->AppDateTime))
									{
										$this->SetValByKey_String_F($attr->getKey(), $DataType->getCurrentDataTime());
									}
									continue;
								}
								else
								{
									continue;
								}
		}
	}
	public function ResetDefaultVal () 
	{
			/* match: String_String_I */
		$this->ResetDefaultVal_String_String_I($this, NULL, 0);
	}
	public function ResetDefaultVal_String_String_I_MapAttrs ($fk_mapdata, $fk_flow, $fk_node, $attrs) // [String fk_mapdata, String fk_flow, int fk_node, MapAttrs attrs]
	{
		foreach ($attrs->ToJavaList() as $attr) 		{
			if (($attr->getLGType() == $BP->En->FieldTypeS->FK))
				$this->SetValRefTextByKey($attr->getKeyOfEn(), "");
			$v = $attr->getDefValReal();
			if ((($v . NULL) . ((($v . NULL) . ($v->contains("@") ==  FALSE )))))
				continue;
			/* match: String */
			$myval = $this->GetValStringByKey_String($attr->getKeyOfEn());
			if (($v->indexOf('@') != 0))
			{
				if (is_null($myval) || $myval == '' || $v == $myval)
				{
					$this->SetValByKey_String_F($attr->getKeyOfEn(), $WebUser->getNo());
				}
			}
			if ($v->equals("@WebUser.getNo()"))
			{
				if ($attr->getUIIsEnable())
				{
					$this->SetValByKey_String_F($attr->getKeyOfEn(), $WebUser->getNo());
				}
				else
				{
					if (is_null($myval) || $myval == '' || $v == $myval)
					{
						$this->SetValByKey_String_F($attr->getKeyOfEn(), $WebUser->getNo());
					}
				}
				continue;
			}
			if ($v->equals("@WebUser.getName()"))
			{
				if ($attr->getUIIsEnable())
				{
					$this->SetValByKey_String_F($attr->getKeyOfEn(), $WebUser->getName());
				}
				else
				{
					if (is_null($myval) || $myval == '' || $v == $myval)
					{
						$this->SetValByKey_String_F($attr->getKeyOfEn(), $WebUser->getName());
					}
				}
				continue;
			}
			if ($v->equals("@WebUser.getFK_Dept()"))
			{
				if ($attr->getUIIsEnable())
				{
					$this->SetValByKey_String_F($attr->getKeyOfEn(), $WebUser->getFK_Dept());
				}
				else
				{
					if (is_null($myval) || $myval == '' || $v == $myval)
					{
						$this->SetValByKey_String_F($attr->getKeyOfEn(), $WebUser->getFK_Dept());
					}
				}
				continue;
			}
			if ($v->equals("@WebUser.getFK_DeptName"))
			{
				if ($attr->getUIIsEnable())
				{
					$this->SetValByKey_String_F($attr->getKeyOfEn(), $WebUser->getFK_DeptName());
				}
				else
				{
					if (is_null($myval) || $myval == '' || $v == $myval)
					{
						$this->SetValByKey_String_F($attr->getKeyOfEn(), $WebUser->getFK_DeptName());
					}
				}
				continue;
			}
			if (($v->equals("@WebUser.getFK_DeptNameOfFull") || $v->equals("@WebUser.getFK_DeptFullName")))
			{
				if ($attr->getUIIsEnable())
				{
					$this->SetValByKey_String_F($attr->getKeyOfEn(), $WebUser->getFK_DeptNameOfFull());
				}
				else
				{
					if (is_null($myval) || $myval == '' || $v == $myval)
					{
						$this->SetValByKey_String_F($attr->getKeyOfEn(), $WebUser->getFK_DeptNameOfFull());
					}
				}
				continue;
			}
			if ($v->equals("@RDT"))
			{
				if ($attr->getUIIsEnable())
				{
					if ((($attr->getMyDataType() == $DataType->AppDate) || $v->equals($myval)))
					{
						$this->SetValByKey_String_F($attr->getKeyOfEn(), $DataType->getCurrentDateByFormart("yyyy-MM-dd"));
					}
					if ((($attr->getMyDataType() == $DataType->AppDateTime) || $v->equals($myval)))
					{
						$this->SetValByKey_String_F($attr->getKeyOfEn(), $DataType->getCurrentDataTime());
					}
				}
				else
				{
					if (is_null($myval) || $myval == '' || $v == $myval)
					{
						if (($attr->getMyDataType() == $DataType->AppDate))
						{
							$this->SetValByKey_String_F($attr->getKeyOfEn(), $DataType->getCurrentDateByFormart("yyyy-MM-dd"));
						}
						else
						{
							$this->SetValByKey_String_F($attr->getKeyOfEn(), $DataType->getCurrentDataTime());
						}
					}
				}
				continue;
			}
			if ($v->equals("@FK_ND"))
			{
				if (($attr->getUIIsEnable() ==  TRUE ))
				{
					$this->SetValByKey_String_F($attr->getKeyOfEn(), $DataType->getCurrentYear());
				}
				else
				{
					if (($DataType->IsNullOrEmpty($myval) || $myval->equals($v)))
						$this->SetValByKey_String_F($attr->getKeyOfEn(), $DataType->getCurrentYear());
				}
				continue;
			}
			if (((($v->equals("@yyyy年mm月dd�?") || $v->equals("@yyyy年mm月dd日HH时mm�?")) || $v->equals("@yy年mm月dd�?")) || $v->equals("@yy年mm月dd日HH时mm�?")))
			{
				if (($attr->getUIIsEnable() ==  TRUE ))
				{
					$this->SetValByKey_String_F($attr->getKeyOfEn(), $DataType->getCurrentDateByFormart($v->replace("@", "")));
				}
				else
				{
					if (($DataType->IsNullOrEmpty($myval) || $myval->equals($v)))
						$this->SetValByKey_String_F($attr->getKeyOfEn(), $DataType->getCurrentDateByFormart($v->replace("@", "")));
				}
				continue;
			}
			else
			{
				$gloVar = new GloVar();
				$gloVar->setNo($v);
				$count = $gloVar->RetrieveFromDBSources();
				if (($count == 1))
				{
					$sql = $gloVar->getVal();
					$sql = $BP->WF->Glo->DealExp($sql, NULL, NULL);
					if (($DataType->IsNullOrEmpty($myval) || $myval->equals($v)))
					{
						try 
						{
							$v = DBAccess->RunSQLReturnString($sql);
							$this->SetValByKey_String_String($attr->getKeyOfEn(), $v);
						}
						catch (Exception $e)
						{
							$this->SetValByKey_String_String($attr->getKeyOfEn(), ($e->getMessage() . $sql));
						}
					}
				}
				continue;
			}
		}
	}
	public function ResetDefaultVal_String_String_I ($fk_mapdata, $fk_flow, $fk_node) // [String fk_mapdata, String fk_flow, int fk_node]
	{
		$this->ResetDefaultValRowValues();
		$attrs = $this->getEnMap()->getAttrs();
		foreach ($attrs as $attr) 		{
			if ($attr->getIsRefAttr())
				$this->SetValRefTextByKey($attr->getKey(), "");
			$frmField = new FrmField();
			$i = 0;
			if (((($fk_node != 0) && ($fk_node != 999999)) . ($fk_flow . NULL)))
				$i = $frmField->Retrieve($FrmFieldAttr->FK_MapData, $fk_mapdata, $FrmFieldAttr->FK_Flow, $Integer->parseInt($fk_flow), $FrmFieldAttr->FK_Node, $fk_node, $FrmFieldAttr->KeyOfEn, $attr->getKey());
			$v = $attr->getDefaultValOfReal();
			if (($i == 1))
			{
				$v = $frmField->getDefVal();
				if ($DataType->IsNullOrEmpty($v))
				{
					$v = $attr->getDefaultValOfReal();
				}
				else
				{
					if (($v->contains("@") ==  FALSE ))
					{
						$this->SetValByKey_String_String($attr->getKey(), $v);
						continue;
					}
				}
			}
			if ((($DataType->IsNullOrEmpty($v) ==  TRUE ) . ((($v . NULL) . ($v->contains("@") ==  FALSE )))))
				continue;
			/* match: String */
			$myval = $this->GetValStringByKey_String($attr->getKey());
			if (($v->indexOf('@') != 0))
			{
				if (is_null($myval) || $myval == '' || $v == $myval)
				{
					$this->SetValByKey_String_F($attr->getKey(), $WebUser->getNo());
				}
			}
			if ($v->equals("@WebUser.getNo()"))
			{
				if ($attr->getUIIsReadonly())
				{
					$this->SetValByKey_String_F($attr->getKey(), $WebUser->getNo());
				}
				else
				{
					if (is_null($myval) || $myval == '' || $v == $myval)
					{
						$this->SetValByKey_String_F($attr->getKey(), $WebUser->getNo());
					}
				}
				continue;
			}
			if ($v->equals("@WebUser.getName()"))
			{
				if ($attr->getUIIsReadonly())
				{
					$this->SetValByKey_String_F($attr->getKey(), $WebUser->getName());
				}
				else
				{
					if (is_null($myval) || $myval == '' || $v == $myval)
					{
						$this->SetValByKey_String_F($attr->getKey(), $WebUser->getName());
					}
				}
				continue;
			}
			if ($v->equals("@WebUser.getFK_Dept()"))
			{
				if ($attr->getUIIsReadonly())
				{
					$this->SetValByKey_String_F($attr->getKey(), $WebUser->getFK_Dept());
				}
				else
				{
					if (is_null($myval) || $myval == '' || $v == $myval)
					{
						$this->SetValByKey_String_F($attr->getKey(), $WebUser->getFK_Dept());
					}
				}
				continue;
			}
			if ($v->equals("@WebUser.getFK_DeptName"))
			{
				if ($attr->getUIIsReadonly())
				{
					$this->SetValByKey_String_F($attr->getKey(), $WebUser->getFK_DeptName());
				}
				else
				{
					if (is_null($myval) || $myval == '' || $v == $myval)
					{
						$this->SetValByKey_String_F($attr->getKey(), $WebUser->getFK_DeptName());
					}
				}
				continue;
			}
			if (($v->equals("@WebUser.getFK_DeptNameOfFull") || $v->equals("@WebUser.getFK_DeptFullName")))
			{
				if ($attr->getUIIsReadonly())
				{
					$this->SetValByKey_String_F($attr->getKey(), $WebUser->getFK_DeptNameOfFull());
				}
				else
				{
					if (is_null($myval) || $myval == '' || $v == $myval)
					{
						$this->SetValByKey_String_F($attr->getKey(), $WebUser->getFK_DeptNameOfFull());
					}
				}
				continue;
			}
			if ($v->equals("@RDT"))
			{
				if ($attr->getUIIsReadonly())
				{
					if ((($attr->getMyDataType() == $DataType->AppDate) || $v->equals($myval)))
					{
						$this->SetValByKey_String_F($attr->getKey(), $DataType->getCurrentDateByFormart("yyyy-MM-dd"));
					}
					if ((($attr->getMyDataType() == $DataType->AppDateTime) || $v->equals($myval)))
					{
						$this->SetValByKey_String_F($attr->getKey(), $DataType->getCurrentDataTime());
					}
				}
				else
				{
					if (is_null($myval) || $myval == '' || $v == $myval)
					{
						if (($attr->getMyDataType() == $DataType->AppDate))
						{
							$this->SetValByKey_String_F($attr->getKey(), $DataType->getCurrentDateByFormart("yyyy-MM-dd"));
						}
						else
						{
							$this->SetValByKey_String_F($attr->getKey(), $DataType->getCurrentDataTime());
						}
					}
				}
				continue;
			}
			if ($v->equals("@FK_ND"))
			{
				if (($attr->getUIIsReadonly() ==  TRUE ))
				{
					$this->SetValByKey_String_F($attr->getKey(), $DataType->getCurrentYear());
				}
				else
				{
					if (($DataType->IsNullOrEmpty($myval) || $myval->equals($v)))
						$this->SetValByKey_String_F($attr->getKey(), $DataType->getCurrentYear());
				}
				continue;
			}
			if (((($v->equals("@yyyy年mm月dd�?") || $v->equals("@yyyy年mm月dd日HH时mm�?")) || $v->equals("@yy年mm月dd�?")) || $v->equals("@yy年mm月dd日HH时mm�?")))
			{
				if (($attr->getUIIsReadonly() ==  TRUE ))
				{
					$this->SetValByKey_String_F($attr->getKey(), $DataType->getCurrentDateByFormart($v->replace("@", "")));
				}
				else
				{
					if (($DataType->IsNullOrEmpty($myval) || $myval->equals($v)))
						$this->SetValByKey_String_F($attr->getKey(), $DataType->getCurrentDateByFormart($v->replace("@", "")));
				}
				continue;
			}
			else
			{
				$gloVar = new GloVar();
				$gloVar->setNo($v);
				$count = $gloVar->RetrieveFromDBSources();
				if (($count == 1))
				{
					$sql = $gloVar->getVal();
					$sql = $BP->WF->Glo->DealExp($sql, NULL, NULL);
					if (($DataType->IsNullOrEmpty($myval) || $myval->equals($v)))
					{
						try 
						{
							$v = DBAccess->RunSQLReturnString($sql);
							$this->SetValByKey_String_String($attr->getKey(), $v);
						}
						catch (Exception $e)
						{
							$this->SetValByKey_String_String($attr->getKey(), ($e->getMessage() . $sql));
						}
					}
				}
				continue;
			}
		}
	}
	public function ResetDefaultValAllAttr () 
	{
		$attrs = $this->getEnMap()->getAttrs();
		foreach ($attrs as $attr) 		{
			if ((!$attr->getUIIsReadonly() && ($attr->getDefaultValOfReal() != NULL)))
			{
				continue;
			}
			if ($attr->getIsPK())
			{
				continue;
			}
			$tempVar = $attr->getDefaultValOfReal();
			$v = (( (($tempVar instanceof String)) ? $tempVar : NULL ));
			if (($v . NULL))
			{
				$this->SetValByKey_String_String($attr->getKey(), "");
				continue;
			}
			if (((!$v->contains("@") || $v->equals("0")) || $v->equals("0.00")))
			{
				$this->SetValByKey_String_String($attr->getKey(), $v);
				continue;
			}
			if ($v->equals("WebUser.getNo()"))
			{
				$this->SetValByKey_String_F($attr->getKey(), $WebUser->getNo());
				continue;
			}
			else
				if ($v->equals("@WebUser.getName()"))
				{
					$this->SetValByKey_String_F($attr->getKey(), $WebUser->getName());
					continue;
				}
				else
					if ($v->equals("@WebUser.getFK_Dept()"))
					{
						$this->SetValByKey_String_F($attr->getKey(), $WebUser->getFK_Dept());
						continue;
					}
					else
						if ($v->equals("@WebUser.getFK_DeptName"))
						{
							$this->SetValByKey_String_F($attr->getKey(), $WebUser->getFK_DeptName());
							continue;
						}
						else
							if ($v->equals("@WebUser.getFK_DeptNameOfFull"))
							{
								$this->SetValByKey_String_F($attr->getKey(), $WebUser->getFK_DeptNameOfFull());
								continue;
							}
							else
								if ($v->equals("@RDT"))
								{
									if (($attr->getMyDataType() == $DataType->AppDate))
									{
										$this->SetValByKey_String_F($attr->getKey(), $DataType->getCurrentDateByFormart("yyyy-MM-dd"));
									}
									else
									{
										$this->SetValByKey_String_F($attr->getKey(), $DataType->getCurrentDataTime());
									}
									continue;
								}
								else
								{
									continue;
								}
		}
	}
	protected function get_enMap () 
	{
		if (($this->_tmpEnMap != NULL))
		{
			return $this->_tmpEnMap;
		}
		$obj = $Cash->GetMap($this);
		if (($obj == NULL))
		{
			if (($this->_tmpEnMap == NULL))
			{
				return NULL;
			}
			else
			{
				return $this->_tmpEnMap;
			}
		}
		else
		{
			$this->_tmpEnMap = $obj;
		}
		return $this->_tmpEnMap;
	}
	protected function set_enMap ($value) // [Map value]
	{
		if (($value == NULL))
		{
			$this->_tmpEnMap = NULL;
			return ;
		}
		$mp = $value;
		if ((($mp == NULL) || ($mp->getDepositaryOfMap() == $Depositary->None)))
		{
			$this->_tmpEnMap = $mp;
			return ;
		}
		$Cash->SetMap($this, $mp);
		$this->_tmpEnMap = $mp;
	}
	public function setMap ($value) // [Map value]
	{
		$this->set_enMap($value);
	}
	abstract function getEnMap (); 
	public function getEnMapInTime () 
	{
		$this->_tmpEnMap = NULL;
		$Cash->SetMap($this->getClass()->getName(), NULL);
		return $this->getEnMap();
	}
	public function getRow () 
	{
		if (($this->_row == NULL))
		{
			$this->_row = new Row();
			$this->_row->LoadAttrs($this->getEnMap()->getAttrs());
		}
		return $this->_row;
	}
	public function setRow ($value) // [Row value]
	{
		$this->_row = $value;
	}
	public function getSQLCash () 
	{
		if (($this->_SQLCash == NULL))
		{
			$this->_SQLCash =Cash->GetSQL($this);
			if (($this->_SQLCash == NULL))
			{
				$this->_SQLCash = SQLCash::constructor__Entity($this);
				Cash->SetSQL($this, $this->_SQLCash);
			}
		}
		return $this->_SQLCash;
	}
	public function setSQLCash ($value) // [SQLCash value]
	{
		$this->_SQLCash = $value;
	}
	public function clearSQLCash () 
	{
		Cash->getSQL_Cash()->remove($this);
		$this->_SQLCash = NULL;
	}
	public function SetValByKey_String_String ($attrKey, $val) // [String attrKey, String val]
	{
		if (($val . NULL))
		{
			$val = "";
		}
		$this->getRow()->SetValByKey($attrKey, $val);
	}
	public function SetValByKey_String_I ($attrKey, $val) // [String attrKey, int val]
	{
		$this->getRow()->SetValByKey($attrKey, $val);
	}
	public function SetValByKey_String_L ($attrKey, $val) // [String attrKey, long val]
	{
		$this->getRow()->SetValByKey($attrKey, $val);
	}
	public function SetValByKey_String_F ($attrKey, $val) // [String attrKey, float val]
	{
		$this->getRow()->SetValByKey($attrKey, $val);
	}
	public function SetValByKey_String_BigDecimalmathjava ($attrKey, $val) // [String attrKey, java.math.BigDecimal val]
	{
		$this->getRow()->SetValByKey($attrKey, $val);
	}
	public function SetValByKey_String_Object ($attrKey, $val) // [String attrKey, Object val]
	{
		$this->getRow()->SetValByKey($attrKey, $val);
	}
	public function SetValByDesc ($attrDesc, $val) // [String attrDesc, Object val]
	{
		if (($val == NULL))
		{
			throw new \RuntimeException((("@不能设置属�?�[" . $attrDesc) . "]null 值�??"));
		}
		$this->getRow()->SetValByKey($this->getEnMap()->GetAttrByDesc($attrDesc)->getKey(), $val);
	}
	public function SetValRefTextByKey ($attrKey, $val) // [String attrKey, Object val]
	{
		$this->SetValByKey_String_Object(($attrKey . "Text"), $val);
	}
	public function SetValByKey_String_b ($attrKey, $val) // [String attrKey, boolean val]
	{
		if ($val)
		{
			$this->SetValByKey_String_I($attrKey, 1);
		}
		else
		{
			$this->SetValByKey_String_I($attrKey, 0);
		}
	}
	public function SetDefaultVals () 
	{
		foreach ($this->getEnMap()->getAttrs() as $attr) 		{
			$this->SetValByKey_String_F($attr->getKey(), $attr->getDefaultVal());
		}
	}
	public function SetDateValByKey ($attrKey, $val) // [String attrKey, String val]
	{
		try 
		{
			$this->SetValByKey_String_F($attrKey, $DataType->StringToDateStr($val));
		}
		catch (\RuntimeException $ex)
		{
			throw new \RuntimeException(((((("@不合法的日期数据格式:key=[" . $attrKey) . "],value=") . $val) . " ") . $ex->getMessage()));
		}
	}
	public function GetValByKey ($attrKey) // [String attrKey]
	{
		return $this->getRow()->GetValByKey($attrKey);
	}
	public function GetValDateTime ($attrKey) // [String attrKey]
	{
			/* match: String */
		return $DataType->ParseSysDateTime2DateTime($this->GetValStringByKey_String($attrKey));
	}
	public function GetValStrByKey_String ($key) // [String key]
	{
		$value = $this->getRow()->GetValByKey($key);
		if ((NULL == $value))
		{
			return "";
		}
		return $value;
	}
	public function GetValStrByKey_String_String ($key, $isNullAs) // [String key, String isNullAs]
	{
		$obj = $this->getRow()->get($key);
		if (($obj == NULL))
			return $isNullAs;
		return $obj;
	}
	public function GetValStringByKey_String ($attrKey) // [String attrKey]
	{
			/* match: String_String */
		$val = $this->GetValStrByKey_String_String($attrKey, NULL);
		if (($val . NULL))
			throw new \RuntimeException(((("@获取值期间出现如下异常：  " . $attrKey) . " 您没有在类增加这个属性，EnName=") . $this));
		return $val;
	}
	public function GetValStringByKey_String_String ($attrKey, $isNullAsVal) // [String attrKey, String isNullAsVal]
	{
			/* match: String_String */
		$val = $this->GetValStrByKey_String_String($attrKey, NULL);
		if (($val . NULL))
			return $isNullAsVal;
		return $val;
	}
	public function GetValDocText () 
	{
			/* match: String */
		$s = $this->GetValStrByKey_String("Doc");
		if (($s->trim()->length() != 0))
		{
			return $s;
		}
		$this->SetValByKey_String_String("Doc", $s);
		return $s;
	}
	public function GetValDocHtml () 
	{
			/* match: String */
		$s = $this->GetValHtmlStringByKey_String("Doc");
		if (($s->trim()->length() != 0))
		{
			return $s;
		}
		$s = $SysDocFile->GetValHtmlV2($this, $this->getPKVal());
		$this->SetValByKey_String_String("Doc", $s);
		return $s;
	}
	public function GetValHtmlStringByKey_String ($attrKey) // [String attrKey]
	{
			/* match: String */
		return $DataType->ParseText2Html($this->GetValStringByKey_String($attrKey));
	}
	public function GetValHtmlStringByKey_String_String ($attrKey, $defval) // [String attrKey, String defval]
	{
			/* match: String_String */
		return $DataType->ParseText2Html($this->GetValStringByKey_String_String($attrKey, $defval));
	}
	public function GetValRefTextByKey ($attrKey) // [String attrKey]
	{
			/* match: String */
		return $this->GetValStringByKey_String(($attrKey . "Text"));
	}
	public function GetValInt64ByKey ($key) // [String key]
	{
			/* match: String_String */
		$val = $this->GetValStringByKey_String_String($key, "0");
		if ($DataType->IsNullOrEmpty($val))
			$val = "0";
		return $Long->parseLong($val);
	}
	public function GetValIntByKey_String_I ($key, $IsZeroAs) // [String key, int IsZeroAs]
	{
			/* match: String */
		$i = $this->GetValIntByKey_String($key);
		if (($i == 0))
		{
			$i = $IsZeroAs;
		}
		return $i;
	}
	public function GetValIntByKey_String ($key) // [String key]
	{
			/* match: String */
		$val = $this->GetValStringByKey_String($key);
		if ($DataType->IsNullOrEmpty($val))
			return 0;
		if (($val->endsWith(".0") ==  TRUE ))
			$val = $val->replace(".0", "");
		return $Integer->parseInt($val);
	}
	public function GetValBooleanByKey_String_b ($key, $IsNullBoolean) // [String key, boolean IsNullBoolean]
	{
			/* match: String */
		$s = $this->GetValStrByKey_String($key);
		if ($DataType->IsNullOrEmpty($s))
			$s = $this->getEnMap()->GetAttrByKey($key)->getDefaultVal();
		if ($s->equals("0"))
			return  FALSE ;
		if ($s->equals("1"))
			return  TRUE ;
		if ($s->toUpperCase()->equals("FALSE"))
			return  FALSE ;
		if ($s->toUpperCase()->equals("TRUE"))
			return  TRUE ;
		if ($DataType->IsNullOrEmpty($s))
			return  FALSE ;
		if (($Integer->parseInt($s) == 0))
			return  FALSE ;
		return $IsNullBoolean;
	}
	public function GetValBooleanByKey_String ($key) // [String key]
	{
			/* match: String_b */
		return $this->GetValBooleanByKey_String_b($key,  TRUE );
	}
	public function GetValBoolStrByKey ($key) // [String key]
	{
			/* match: String */
		if (($this->GetValBooleanByKey_String($key) ==  FALSE ))
		{
			return "�?";
		}
		else
		{
			return "�?";
		}
	}
	public function GetValFloatByKey_String_I ($key, $blNum) // [String key, int blNum]
	{
			/* match: String */
		$val = $this->GetValStringByKey_String($key);
		if ($DataType->IsNullOrEmpty($val))
			return $blNum;
		return $Float->parseFloat($val);
	}
	public function GetValFloatByKey_String ($key) // [String key]
	{
			/* match: String */
		$val = $this->GetValStringByKey_String($key);
		if (($val . NULL))
			return 0;
		return $Float->parseFloat($val);
	}
	public function GetValDecimalByKey_String ($key) // [String key]
	{
			/* match: String */
		$bd = new BigDecimal($this->GetValStrByKey_String($key));
		return $bd->setScale(4, $BigDecimal->ROUND_HALF_UP);
	}
	public function GetValDecimalByKey_String_I ($key, $scale) // [String key, int scale]
	{
			/* match: String */
		$bd = new BigDecimal($this->GetValStrByKey_String($key));
		return $bd->setScale($scale, $BigDecimal->ROUND_HALF_UP);
	}
	public function GetValDoubleByKey ($key) // [String key]
	{
			/* match: String */
		$val = $this->GetValStrByKey_String($key);
		if (($val . NULL))
			return 0;
		return $Double->parseDouble($val);
	}
	public function getIsBlank () 
	{
		if (($this->_row == NULL))
		{
			return  TRUE ;
		}
		$attrs = $this->getEnMap()->getAttrs();
		foreach ($attrs as $attr) 		{
			if (($attr->getUIIsReadonly() && !$attr->getIsFKorEnum()))
			{
				continue;
			}
			/* match: String */
			$str = $this->GetValStrByKey_String($attr->getKey());
			if (((($str . NULL) . $str->equals("")) . $attr->getDefaultVal()->equals($str)))
			{
				continue;
			}
			if ((($attr->getMyDataType() == $DataType->AppDate) && ($attr->getDefaultVal() == NULL)))
			{
				if ($DataType->getCurrentDateByFormart("yyyy-MM-dd")->equals($str))
				{
					continue;
				}
				else
				{
					return  TRUE ;
				}
			}
			if (($attr->getDefaultVal()->equals($str) && !$attr->getIsFK()))
			{
				continue;
			}
			if ($attr->getIsEnum())
			{
				if ($attr->getDefaultVal()->equals($str))
				{
					continue;
				}
				else
				{
					return  FALSE ;
				}
			}
			if ($attr->getIsNum())
			{
				if (((new BigDecimal($str))->compareTo(new BigDecimal($attr->getDefaultVal())) != 0))
				{
					return  FALSE ;
				}
				else
				{
					continue;
				}
			}
			if ($attr->getIsFKorEnum())
			{
				if (!$attr->getDefaultVal()->equals($str))
				{
					return  FALSE ;
				}
				else
				{
					continue;
				}
			}
			if (!$attr->getDefaultVal()->equals($str))
			{
				return  FALSE ;
			}
		}
		return  TRUE ;
	}
	public function getIsEmpty () 
	{
		if (($this->_row == NULL))
			return  TRUE ;
		if (((($this->getPKVal() == NULL) || $this->getPKVal()->equals("0")) || $this->getPKVal()->equals("")))
		{
			return  TRUE ;
		}
		return  FALSE ;
	}
	public function setIsEmpty () 
	{
		$this->_row = NULL;
	}
	public function getEnDesc () 
	{
		return $this->getEnMap()->getEnDesc();
	}
	public function getPKVal () 
	{
		return $this->GetValByKey($this->getPK());
	}
	public function setPKVal ($value) // [Object value]
	{
		$this->SetValByKey_String_Object($this->getPK(), $value);
	}
	public function getPKCount () 
	{
		if ((((($this->getPK()->equals("OID") || $this->getPK()->equals("No")) || $this->getPK()->equals("MyPK")) || $this->getPK()->equals("NodeID")) || $this->getPK()->equals("WorkID")))
		{
			return 1;
		}
		$i = 0;
		foreach ($this->getEnMap()->getAttrs() as $attr) 		{
			if (((($attr->getMyFieldType() == FieldType::$PK) || ($attr->getMyFieldType() == FieldType::$PKEnum)) || ($attr->getMyFieldType() == FieldType::$PKFK)))
			{
				++$i;
			}
		}
		if (($i == 0))
		{
			throw new \RuntimeException((((("@没有给�??" . $this->getEnDesc()) . "�?") . $this->getEnMap()->getPhysicsTable()) . "】定义主键�??"));
		}
		else
		{
			return $i;
		}
	}
	public function getIsOIDEntity () 
	{
		if ($this->getPK()->equals("OID"))
		{
			return  TRUE ;
		}
		return  FALSE ;
	}
	public function getIsNoEntity () 
	{
		if ($this->getPK()->equals("No"))
		{
			return  TRUE ;
		}
		return  FALSE ;
	}
	public function getIsTreeEntity () 
	{
		return $this->getEnMap()->getAttrs()->Contains("ParentNo");
	}
	public function getPK () 
	{
		$pks = "";
		foreach ($this->getEnMap()->getAttrs() as $attr) 		{
			if (((($attr->getMyFieldType() == FieldType::$PK) || ($attr->getMyFieldType() == FieldType::$PKEnum)) || ($attr->getMyFieldType() == FieldType::$PKFK)))
			{
				$pks += ($attr->getKey() . ",");
			}
		}
		if ($pks->equals(""))
		{
			throw new \RuntimeException((((("@没有给�??" . $this->getEnDesc()) . "�?") . $this->getEnMap()->getPhysicsTable()) . "】定义主键�??"));
		}
		$pks = $pks->substring(0, ($pks->length() - 1));
		return $pks;
	}
	public function getPKs () 
	{
		$strs1 = array();
		$i = 0;
		foreach ($this->getEnMap()->getAttrs() as $attr) 		{
			if (((($attr->getMyFieldType() == FieldType::$PK) || ($attr->getMyFieldType() == FieldType::$PKEnum)) || ($attr->getMyFieldType() == FieldType::$PKFK)))
			{
				$strs1[$i] = $attr->getKey();
				++$i;
			}
		}
		return $strs1;
	}
	public function getPKVals () 
	{
		$ht = new Hashtable();
		$strs = $this->getPKs();
		foreach ($strs as $str) 		{
			/* match: String */
			$ht->put($str, $this->GetValStringByKey_String($str));
		}
		return $ht;
	}
}
Entity::__staticinit(); // initialize static vars for this class on load
?>
